calculating time difference from two string dates

I have string dates say (05.01.1993 17:40:00) and (07.01.1993 09:50:00) is there a way to calculate the number of months/days/hours between these two dates?

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 22 日

0 投票

date1=datenum(1993,5,1)
date2=datenum(1993,7,1)
v=datestr(datenum(date1:date2))
n=numel(v) %number of days

3 件のコメント

Meh
Meh 2013 年 2 月 22 日
Thank you! but can this method aslo calculate the number of minutes between the two dates?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 22 日
%-------Number of days--------
date1=datenum(1993,5,1)
date2=datenum(1993,7,1)
v=datestr(datenum(date1:date2))
n=numel(v) %number of days
%-------Number of minutes--------
d2=('09:50:00')
d1=('17:40:00')
minut=hour(d2)*60+minute(d2)-(hour(d1)*60+minute(d1))
Result=n*24*60+minut
Tunechi
Tunechi 2015 年 8 月 12 日
編集済み: Tunechi 2015 年 8 月 12 日
I think numel is not counting the number of days instead I used length(v)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

タグ

質問済み:

Meh
2013 年 2 月 22 日

編集済み:

2015 年 8 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by