Azzera filtri
Azzera filtri

How to count the number of hours with reference to a MATLAB formatted date?

2 visualizzazioni (ultimi 30 giorni)
Using MATLAB datenum function, one can generate date patterns like 7.3560e+05. This represents 03-Jan-2014 02:00:00.
If I want to count the number of hours (for e.g. in this case: 50 hrs) of this number from 01-Jan-2013 00:00:00, how can I do it? I want to generalize for any datenum formatted date.
Thanks.

Risposta accettata

Joseph Cheng
Joseph Cheng il 20 Ago 2014
the number returned from datenum is in days. so if we go
time1 = datenum(datestr(now));
pause(1);
time2 = datenum(datestr(now));
deltaTime = (time2-time1)*24*60*60
then we should get deltaTime = 1 (second). So to count the hours we can go
time1 = datenum(datestr(now));
current_time = datestr(time1)
twodayslater = datestr(time1+50/24)
such that the 50 hours later is 2days 2 hours so we can see that when comparing the current_time to twodayslater.
  2 Commenti
Joseph Cheng
Joseph Cheng il 20 Ago 2014
so for your arbitrary datestr formatted date you can go
datestr(datenum(' 01-Jan-2013 00:00:00') +50/24)
As long as your date string is accepted into datenum you can go back and forth.
Ashish
Ashish il 20 Ago 2014
Thanks Joseph for the detailed explanation. Certainly helped.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by