Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MATLAB date issue

Subject: MATLAB date issue

From: Sudip

Date: 13 Sep, 2013 18:57:06

Message: 1 of 5

I am trying to convert NCEP 2 reanalysis dates to a matlab date format.
 The time-series I am using from NCEP has a starting time : time(1)= 1709328;
with a reference, 'hours since 1800-1-1 00:00:0.0 (dj=datenum(1800,1,1))''. Matlab uses a different reference date which is dm=datenum(1950,1,1)
when I use the date-shift (dm-dj) and try to use datestr to find the date for time(1)=1709328, it gives me datestr(time(1)-dj+dm)
ans =23-Dec-4829----- which does not make sense.

When I use ---datestr(time(1)+dj-dm)

ans =24-Dec-4529---- it does not make sense too.

Can anybody help to get the exact time for datenum=1709328

Thanks in advance,
Sudip

Subject: MATLAB date issue

From: James Tursa

Date: 13 Sep, 2013 19:09:05

Message: 2 of 5

"Sudip" wrote in message <l0vn62$6tj$1@newscl01ah.mathworks.com>...
> I am trying to convert NCEP 2 reanalysis dates to a matlab date format.
> The time-series I am using from NCEP has a starting time : time(1)= 1709328;
> with a reference, 'hours since 1800-1-1 00:00:0.0 (dj=datenum(1800,1,1))''. Matlab uses a different reference date which is dm=datenum(1950,1,1)
> when I use the date-shift (dm-dj) and try to use datestr to find the date for time(1)=1709328, it gives me datestr(time(1)-dj+dm)
> ans =23-Dec-4829----- which does not make sense.
>
> When I use ---datestr(time(1)+dj-dm)
>
> ans =24-Dec-4529---- it does not make sense too.
>
> Can anybody help to get the exact time for datenum=1709328
>
> Thanks in advance,
> Sudip

I don't know what you mean by the statement "Matlab uses a different reference date which is dm=datenum(1950,1,1)" ... MATLAB datenum uses year 000 as a reference, not 1950. In any event, here is what I get:

>> dj=datenum(1800,1,1)
dj =
      657438
>> datestr(dj + 1709328/24)
ans =
01-Jan-1995


James Tursa

Subject: MATLAB date issue

From: Steven_Lord

Date: 13 Sep, 2013 19:26:30

Message: 3 of 5



"Sudip " <majumdersudip@gmail.com> wrote in message
news:l0vn62$6tj$1@newscl01ah.mathworks.com...
> I am trying to convert NCEP 2 reanalysis dates to a matlab date format.
> The time-series I am using from NCEP has a starting time : time(1)=
> 1709328;
> with a reference, 'hours since 1800-1-1 00:00:0.0
> (dj=datenum(1800,1,1))''. Matlab uses a different reference date which
> is dm=datenum(1950,1,1)
> when I use the date-shift (dm-dj) and try to use datestr to find the date
> for time(1)=1709328, it gives me datestr(time(1)-dj+dm)
> ans =23-Dec-4829----- which does not make sense.

From what you copied, it sounds like NCEP counts in hours: NCEP time 2 is
one hour later than NCEP time 1.

MATLAB date numbers count in DAYS, not hours: MATLAB date number 2 is one
DAY later than MATLAB date number 1.

> When I use ---datestr(time(1)+dj-dm)
>
> ans =24-Dec-4529---- it does not make sense too.

You're adding apples and oranges and expecting to obtain a pie. What you're
getting instead is a smoothie. [Okay, not the greatest of metaphors.]

> Can anybody help to get the exact time for datenum=1709328

Convert the NCEP hours offset to a day offset and add to the NCEP base time.

T = 1709328;
hoursPerDay = 24;
NCEPbase = datenum(1800, 1, 1);
datestr((T/hoursPerDay) + NCEPbase)

This gives me 1 January 1995. Is that what you expect?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: MATLAB date issue

From: Sudip

Date: 16 Sep, 2013 17:02:09

Message: 4 of 5

"Steven_Lord" <slord@mathworks.com> wrote in message <l0vot5$9c9$1@newscl01ah.mathworks.com>...
>
>
> "Sudip " <majumdersudip@gmail.com> wrote in message
> news:l0vn62$6tj$1@newscl01ah.mathworks.com...
> > I am trying to convert NCEP 2 reanalysis dates to a matlab date format.
> > The time-series I am using from NCEP has a starting time : time(1)=
> > 1709328;
> > with a reference, 'hours since 1800-1-1 00:00:0.0
> > (dj=datenum(1800,1,1))''. Matlab uses a different reference date which
> > is dm=datenum(1950,1,1)
> > when I use the date-shift (dm-dj) and try to use datestr to find the date
> > for time(1)=1709328, it gives me datestr(time(1)-dj+dm)
> > ans =23-Dec-4829----- which does not make sense.
>
> From what you copied, it sounds like NCEP counts in hours: NCEP time 2 is
> one hour later than NCEP time 1.
>
> MATLAB date numbers count in DAYS, not hours: MATLAB date number 2 is one
> DAY later than MATLAB date number 1.
>
> > When I use ---datestr(time(1)+dj-dm)
> >
> > ans =24-Dec-4529---- it does not make sense too.
>
> You're adding apples and oranges and expecting to obtain a pie. What you're
> getting instead is a smoothie. [Okay, not the greatest of metaphors.]
>
> > Can anybody help to get the exact time for datenum=1709328
>
> Convert the NCEP hours offset to a day offset and add to the NCEP base time.
>
> T = 1709328;
> hoursPerDay = 24;
> NCEPbase = datenum(1800, 1, 1);
> datestr((T/hoursPerDay) + NCEPbase)
>
> This gives me 1 January 1995. Is that what you expect?
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


That is what I expect. Now I understand where I was wrong in the calculation. Thank you so much.

Subject: MATLAB date issue

From: Sudip

Date: 16 Sep, 2013 17:10:07

Message: 5 of 5

"James Tursa" wrote in message <l0vnsh$jkj$1@newscl01ah.mathworks.com>...
> "Sudip" wrote in message <l0vn62$6tj$1@newscl01ah.mathworks.com>...
> > I am trying to convert NCEP 2 reanalysis dates to a matlab date format.
> > The time-series I am using from NCEP has a starting time : time(1)= 1709328;
> > with a reference, 'hours since 1800-1-1 00:00:0.0 (dj=datenum(1800,1,1))''. Matlab uses a different reference date which is dm=datenum(1950,1,1)
> > when I use the date-shift (dm-dj) and try to use datestr to find the date for time(1)=1709328, it gives me datestr(time(1)-dj+dm)
> > ans =23-Dec-4829----- which does not make sense.
> >
> > When I use ---datestr(time(1)+dj-dm)
> >
> > ans =24-Dec-4529---- it does not make sense too.
> >
> > Can anybody help to get the exact time for datenum=1709328
> >
> > Thanks in advance,
> > Sudip
>
> I don't know what you mean by the statement "Matlab uses a different reference date which is dm=datenum(1950,1,1)" ... MATLAB datenum uses year 000 as a reference, not 1950. In any event, here is what I get:
>
> >> dj=datenum(1800,1,1)
> dj =
> 657438
> >> datestr(dj + 1709328/24)
> ans =
> 01-Jan-1995
>
>
> James Tursa

This is a great help thank you.

Tags for this Thread

No tags are associated with this thread.

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.

Contact us