Calculate difference between two times?...something it's wrong here¡
Afficher commentaires plus anciens
I would be very grateful if someone could help me with the following problem, I try to subtract dates, but clearly the result is not what I expect....look¡
>>date =
2012 9 25 0 0 0
2012 9 23 21 0 0
>>d=datenum(date)
d =
1.0e+05 *
7.3514
7.3514
>>difference=d(1)-d(2);
ans =
1.1250
>>datestr(difference,'yyyy mm dd HH MM SS')
ans =
0000 01 01 03 00 00 % should be 0000 00 01 03 00 00
Thanks
Réponse acceptée
Plus de réponses (1)
What makes you think it should be 0000 00 01 03 00 00?
From the documentation:
A serial date number represents a calendar date as the number of days that has passed since a fixed base date. In MATLAB, serial date number 1 is January 1, 0000.
If you subtract two datenumbers, the result will not be the time elapsed between the two dates.
datevec(723300 - 723297)
If you want the elapsed time:
etime(datevec(723300),datevec(723297)) %in seconds
3 commentaires
Oleg Komarov
le 17 Sep 2014
Modifié(e) : Oleg Komarov
le 17 Sep 2014
For instance, the abse date is January 0, 0000:
datestr(0,'yyyy mm dd')
ans =
0000 01 00
Rapala
le 17 Sep 2014
José-Luis
le 17 Sep 2014
Please accept the answer that best solves your problem.
Catégories
En savoir plus sur Calendar dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!