How can I add serial date and time for each 12 min ?

2 vues (au cours des 30 derniers jours)
Riyadh Muttaleb
Riyadh Muttaleb le 2 Déc 2016
Commenté : Riyadh Muttaleb le 3 Déc 2016
Hello All,
I have date and time like: (2009 10 09 12 36 00), I would like to make a serial date and time that increase each 12 min (that means 36 min will be 48 00 12 24 .....)to date and time for example (2009 10 10 22 24 00).
Please any help: Thanks in advance,
Riyadh

Réponse acceptée

Steven Lord
Steven Lord le 2 Déc 2016
Take a look at this documentation page for some examples of how to do what you want using datetime and duration arrays.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 2 Déc 2016
For serial dates, use addtodate()
For datetime objects, you can
Starting_datetime + minutes(12:12:60)
  3 commentaires
Walter Roberson
Walter Roberson le 3 Déc 2016
t = datenum('07-Apr-2008 23:00:00')
addtodate(t, 12, 'minutes')
the result is a serial date number.
2009 10 09 12 36 00 is datevec form, not serial date numbers. If you want date vector format, then one approach is
minutes_to_add = 12 : 12 : 60;
nm = length(minutes_to_add);
v = [2009 10 09 12 36 00];
new_v = datevec( datenum( repmat(v, nm, 1) + [zeros(nm, 4), minutes_to_add(:), zeros(nm, 1)] ) );
Riyadh Muttaleb
Riyadh Muttaleb le 3 Déc 2016
It is worked, thank you.

Connectez-vous pour commenter.


Andrei Bobrov
Andrei Bobrov le 3 Déc 2016
Modifié(e) : Andrei Bobrov le 3 Déc 2016
a =datetime([2009, 10, 09, 12, 36, 00;2009 10 10 22 24 00])
out = a(1) + (0:minutes(12):diff(a))'
or
a = datenum([2009, 10, 09, 12, 36, 00;2009 10 10 22 24 00])
out = datestr(datenum(2009,10,09,12,(36:12:diff(a)*24*60)',0))
  1 commentaire
Riyadh Muttaleb
Riyadh Muttaleb le 3 Déc 2016
the second one is worked, thank you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by