MATLAB: Convert date to UNIX time

posix timeunix time

Hi,
What combination of date functions do I need to use to convert a date such as '24-Apr-2011' into UNIX time (and vice versa)?
I've been playing around with datenum, datestr and datetick but I can't figure it out
Thanks Dave

Best Answer

In R2014b or later, use datetime:
>> d = datetime('24-Apr-2011')
d =
24-Apr-2011
>> posixtime(d)
ans =
1303603200
>> datetime(1303603200,'ConvertFrom','posixtime')
ans =
24-Apr-2011 00:00:00
Similar syntaxes for Excel serial date numbers, Julian date numbers, and not surprisingly MATLAB date numbers.
Hope this helps.