3

I am new to Matlab. I am trying to use datenum function to parse date string and convert to timestamps(like in Java, getTime()).Then, I want to find out the difference between two dates in seconds.

datenum('2013-02-21T00:39:19Z','yyyy-mm-ddTHH:MM:ss')-datenum('2013-02-21T00:34:19Z','yyyy-mm-ddTHH:MM:ss')

If I run the function above, I get 0.0035 which I have no idea what kind of value it is.

Can someone help please?

Thanks!

0

2 Answers 2

6

Matlab help says:

A serial date number represents the whole and fractional number of days from a fixed, preset date (January 0, 0000).

I reckon your answer is maybe 0.0035 days so to get seconds I guess its

ans*24*60*60
1
  • 1
    Thanks god… I've searched for the matlab date2num "enconding" for hours, thinking it was something complex. I don't believe I didn't read that. Thank you very much, sir! (I think I might need to stop working for a while hahahah)
    – Werner
    May 25, 2013 at 20:36
6

Your result is in datenum format as Dan says. But if you want to find elapsed time in seconds, there is a function that does exactly what you want.

You can use etime to find elapsed time between two date vectors.

d1 = datevec('2013-02-21T00:39:19Z','yyyy-mm-ddTHH:MM:ss');
d2 = datevec('2013-02-21T00:34:19Z','yyyy-mm-ddTHH:MM:ss');

elapsedTime = etime(d1,d2) % Elapsed time in seconds

elapsedTime =

   300

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.