Reputation: 10395
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!
Upvotes: 3
Views: 9482
Reputation: 3636
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
Upvotes: 6
Reputation: 45762
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
Upvotes: 6