Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab convert date string to timestamps using datenum problems

Tags:

matlab

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!

like image 846
leon Avatar asked Nov 25 '25 14:11

leon


2 Answers

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
like image 93
Dan Avatar answered Nov 28 '25 05:11

Dan


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
like image 27
HebeleHododo Avatar answered Nov 28 '25 06:11

HebeleHododo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!