Thread Subject: convert 'dd:mm:yyyy' to [yyyy mm dd]

Subject: convert 'dd:mm:yyyy' to [yyyy mm dd]

From: Mike

Date: 20 Mar, 2010 08:24:59

Message: 1 of 7

Hi

I have a date cell array with form of 'dd:mm:yyyy'.
I want to use datenum later with input like [yyyy mm dd h m s]
How to convert it to [yyyy mm dd]?
thanks.

Mike

Subject: convert 'dd:mm:yyyy' to [yyyy mm dd]

From: TideMan

Date: 20 Mar, 2010 18:54:02

Message: 2 of 7

On Mar 20, 9:24 pm, Mike <sulfate...@gmail.com> wrote:
> Hi
>
> I have a date cell array with form of 'dd:mm:yyyy'.
> I want to use datenum later with input like [yyyy mm dd h m s]
> How to convert it to [yyyy mm dd]?
> thanks.
>
> Mike

You don't have to.
datenum will quite happily take 'dd:mm:yyyy' providing you tell it.

Subject: convert 'dd:mm:yyyy' to [yyyy mm dd]

From: Mike

Date: 21 Mar, 2010 23:48:17

Message: 3 of 7

On Mar 21, 2:54 am, TideMan <mul...@gmail.com> wrote:
> On Mar 20, 9:24 pm, Mike <sulfate...@gmail.com> wrote:
>
> > Hi
>
> > I have a date cell array with form of 'dd:mm:yyyy'.
> > I want to use datenum later with input like [yyyy mm dd h m s]
> > How to convert it to [yyyy mm dd]?
> > thanks.
>
> > Mike
>
> You don't have to.
> datenum will quite happily take 'dd:mm:yyyy' providing you tell it.

I try
>> datenum('01:01:0000')

ans =

    7.341390423611112e+005
Can you tell me how to? thanks.

Mike

Subject: convert 'dd:mm:yyyy' to [yyyy mm dd]

From: TideMan

Date: 21 Mar, 2010 23:56:19

Message: 4 of 7

On Mar 22, 12:48 pm, Mike <sulfate...@gmail.com> wrote:
> On Mar 21, 2:54 am, TideMan <mul...@gmail.com> wrote:
>
> > On Mar 20, 9:24 pm, Mike <sulfate...@gmail.com> wrote:
>
> > > Hi
>
> > > I have a date cell array with form of 'dd:mm:yyyy'.
> > > I want to use datenum later with input like [yyyy mm dd h m s]
> > > How to convert it to [yyyy mm dd]?
> > > thanks.
>
> > > Mike
>
> > You don't have to.
> > datenum will quite happily take 'dd:mm:yyyy' providing you tell it.
>
> I try
>
> >> datenum('01:01:0000')
>
> ans =
>
>     7.341390423611112e+005
> Can you tell me how to? thanks.
>
> Mike

But you didn't tell datenum what format you were using, so datenum
thinks you are entering HH:MM:SS.
Use the 2nd argument to tell it the format:
datenum('01:01:0000','dd:mm:yyyy')
Then to check that datenum has worked correctly, convert it back:
datestr(datenum('01:01:0000','dd:mm:yyyy'))

Subject: convert 'dd:mm:yyyy' to [yyyy mm dd]

From: Mike

Date: 22 Mar, 2010 00:07:19

Message: 5 of 7

On Mar 22, 7:56 am, TideMan <mul...@gmail.com> wrote:
> On Mar 22, 12:48 pm, Mike <sulfate...@gmail.com> wrote:
>
>
>
>
>
> > On Mar 21, 2:54 am, TideMan <mul...@gmail.com> wrote:
>
> > > On Mar 20, 9:24 pm, Mike <sulfate...@gmail.com> wrote:
>
> > > > Hi
>
> > > > I have a date cell array with form of 'dd:mm:yyyy'.
> > > > I want to use datenum later with input like [yyyy mm dd h m s]
> > > > How to convert it to [yyyy mm dd]?
> > > > thanks.
>
> > > > Mike
>
> > > You don't have to.
> > > datenum will quite happily take 'dd:mm:yyyy' providing you tell it.
>
> > I try
>
> > >> datenum('01:01:0000')
>
> > ans =
>
> >     7.341390423611112e+005
> > Can you tell me how to? thanks.
>
> > Mike
>
> But you didn't tell datenum what format you were using, so datenum
> thinks you are entering HH:MM:SS.
> Use the 2nd argument to tell it the format:
> datenum('01:01:0000','dd:mm:yyyy')
> Then to check that datenum has worked correctly, convert it back:
> datestr(datenum('01:01:0000','dd:mm:yyyy'))- Hide quoted text -
>
> - Show quoted text -

Thank you. I thought non-standard format will not work.

Mike

Subject: convert 'dd:mm:yyyy' to [yyyy mm dd]

From: Jan Simon

Date: 22 Mar, 2010 00:11:04

Message: 6 of 7

Dear Mike!

> I have a date cell array with form of 'dd:mm:yyyy'.
> I want to use datenum later with input like [yyyy mm dd h m s]
> How to convert it to [yyyy mm dd]?

A fast method:
  D = '31:12:2010';
  X = sscanf(D, '%d:', 3);
  E = X([3, 2, 1]);
You can call the fast C-Mex DATENUMMX also:
  DNum = datenummx(X(3), X(2), X(1), 0,0,0);

Good luck, Jan

Subject: convert 'dd:mm:yyyy' to [yyyy mm dd]

From: dpb

Date: 22 Mar, 2010 00:55:32

Message: 7 of 7

Mike wrote:
...

> Thank you. I thought non-standard format will not work.

doc datenum % and friends

--

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com