Matlab: date and time

Using now or now() command in Matlab can return current date and time as a serial date number. It is counting how many days has passed A.D.

>> now
ans =
7.3449e+05

Remember there are 365.2422 days in a year.

In case of generating a string, use

>> datestr(now,30)
ans =
20101214T122614
>> datestr(now,31)
ans =
2010-12-14 12:26:22

Format 30 can be used in file names, while format 31 can be used in dates inserted in text. Or you can define your own format:

>> datestr(now,'mmddyyyy')
ans =
12142010

Advertisements
Matlab: date and time