Thread Subject: datenum: default pivot year question...

Subject: datenum: default pivot year question...

From: Andrey Kazak

Date: 13 Jun, 2009 16:55:03

Message: 1 of 3

Greetings!

The extract from MATLAB help for "datenum" function:
N = datenum(S, F, P) converts one or more date strings S to date numbers N using format F and pivot year P. The pivot year is used in interpreting date strings that have the year specified as two characters. It is the starting year of the 100-year range in which a two-character date string year resides. The default pivot year is the current year minus 50 years.

So, as I understand from the text, if current year is 2009 than the default will be 2009 - 50 = 1959. However the command:

datestr(datenum('12.01.13', 'dd.mm.yy'),'dd.mm.yyyy')

gives the following result:

12.01.2013

Year is 2013, but not 1959+13 = 1972.

Could you help me please to figure out what this is: my misunderstanding, wrong help or a bug?

Subject: datenum: default pivot year question...

From: Steven Lord

Date: 13 Jun, 2009 23:46:58

Message: 2 of 3


"Andrey Kazak" <AK@nospam.ru> wrote in message
news:h10ll6$9up$1@fred.mathworks.com...
> Greetings!
>
> The extract from MATLAB help for "datenum" function:
> N = datenum(S, F, P) converts one or more date strings S to date numbers N
> using format F and pivot year P. The pivot year is used in interpreting
> date strings that have the year specified as two characters. It is the
> starting year of the 100-year range in which a two-character date string
> year resides. The default pivot year is the current year minus 50 years.

That's correct.

> So, as I understand from the text, if current year is 2009 than the
> default will be 2009 - 50 = 1959. However the command:
>
> datestr(datenum('12.01.13', 'dd.mm.yy'),'dd.mm.yyyy')
>
> gives the following result:
>
> 12.01.2013
>
> Year is 2013, but not 1959+13 = 1972.
>
> Could you help me please to figure out what this is: my misunderstanding,
> wrong help or a bug?

Because the default pivot year is 1959, that means a 2-digit year
corresponds to the unique year in 1959+(0:99) that has those last two
digits. (0:99) is the "100-year range" referred to in the help, and 1959 is
the starting year of that range. So the year whose last digits are 13
correspond to 2013, since 1959 <= 2013 and 2013 <= 2058 (=1959+99).

--
Steve Lord
slord@mathworks.com

Subject: datenum: default pivot year question...

From: Andrey Kazak

Date: 14 Jun, 2009 03:39:01

Message: 3 of 3

"Steven Lord" <slord@mathworks.com> wrote in message <h11doj$fg8$1@fred.mathworks.com>...
>
> "Andrey Kazak" <AK@nospam.ru> wrote in message
> news:h10ll6$9up$1@fred.mathworks.com...
> > Greetings!
> >
> > The extract from MATLAB help for "datenum" function:
> > N = datenum(S, F, P) converts one or more date strings S to date numbers N
> > using format F and pivot year P. The pivot year is used in interpreting
> > date strings that have the year specified as two characters. It is the
> > starting year of the 100-year range in which a two-character date string
> > year resides. The default pivot year is the current year minus 50 years.
>
> That's correct.
>
> > So, as I understand from the text, if current year is 2009 than the
> > default will be 2009 - 50 = 1959. However the command:
> >
> > datestr(datenum('12.01.13', 'dd.mm.yy'),'dd.mm.yyyy')
> >
> > gives the following result:
> >
> > 12.01.2013
> >
> > Year is 2013, but not 1959+13 = 1972.
> >
> > Could you help me please to figure out what this is: my misunderstanding,
> > wrong help or a bug?
>
> Because the default pivot year is 1959, that means a 2-digit year
> corresponds to the unique year in 1959+(0:99) that has those last two
> digits. (0:99) is the "100-year range" referred to in the help, and 1959 is
> the starting year of that range. So the year whose last digits are 13
> correspond to 2013, since 1959 <= 2013 and 2013 <= 2058 (=1959+99).
>
> --
> Steve Lord
> slord@mathworks.com
>

Thank you, Steven!
Now its clear for me. However, are you sure of range (0:99)?
For example, this command:

datestr(datenum('12-jun-13', 'dd-mmm-yy',1913),'dd.mm.yyyy')

gives

12.06.2013

Year is still 2013, but not 1913 + 0 = 1913.

Perhaps the correct search range for the pivot year is (1:100)?

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
datenum datestr... Andrey Kazak 13 Jun, 2009 12:59:03
rssFeed for this Thread

Contact us at files@mathworks.com