Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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: 17,944
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 " <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




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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.