how deal with date?

2 ビュー (過去 30 日間)
huda nawaf
huda nawaf 2011 年 11 月 3 日
hi, i have data with date as: ex.2005-09-06 are there func. convert this date into another form.
my work require to compare dates to know which event happen before , then I can arranged chronologically .
if is not , can i compare this date 2005-09-06 with another date to know which date earlier. or may there func. can arranged these dates. thanks
  3 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 3 日
The input needs to be data vector or STRING!
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 3 日
It's so funny. 2005-09-06 is treated as subtraction thus the result is 1990. You could also do datenum(2005,9,6) where the input arguments are date vector. See datevec().

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

回答 (3 件)

Daniel Baboiu
Daniel Baboiu 2011 年 11 月 3 日
See the documentation on date conversion functions below: http://www.mathworks.com/help/techdoc/matlab_prog/bspgcx2-1.html#bspgcx3-43
If you have the string in numeric format only (as in your example), in the order yyyy-mm-dd, then you can compare strings directly to get date order.
If you want to convert it to another format, then you must remember to specify the fields, if you use numeric-only notation (your example could be yyyy-mm-dd or yyyy-dd-mm)
  1 件のコメント
Jan
Jan 2011 年 11 月 3 日
You cannot compare two dates in the string format yyyy-mm-dd directly, but you can use SORT to sort them, because then the chronological order equals the alphabetical order.

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


Fangjun Jiang
Fangjun Jiang 2011 年 11 月 3 日
You can convert the date string to numeric and then compare.
a=datenum('2005-09-06');
b=datenum('2005-09-05');
a>b

Bjorn Gustavsson
Bjorn Gustavsson 2011 年 11 月 3 日
Yup, there is. First you have datestr, datevec and datenum. Those should handle most if not all of this task.
HTH,

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by