The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: MATLAB date issue
Replies: 4   Last Post: Sep 16, 2013 1:10 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: MATLAB date issue
Posted: Sep 13, 2013 3:26 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Sudip " <> wrote in message
> 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
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.