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
Sign up to request clarification or add additional context in comments.

1 Comment

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)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.