Datetime with variable format
I have an output file that has timestamps in the form of ‘yyyy-MM-dd HH:mm:ss.S’ or ‘yyyy-MM-dd HH:mm:ss’. I would like a clean way to convert them from date strings into an array of date time format.
Example code:
a={‘2016-02-09 10:28:00′;’2016-02-09 10:28:01.5’}
out=datetime(a,’InputFormat’,’yyyy-MM-dd HH:mm:ss.S’,’InputFormat’,’yyyy-MM-dd HH:mm:ss’,’Format’,’yyyy-MM-dd HH:mm:ss.S’);
Actual output:
out =
2016-02-09 10:28:00.0
NaT
Desired output:
out =
2016-02-09 10:28:00.0
2016-02-09 10:28:00.5I have an output file that has timestamps in the form of ‘yyyy-MM-dd HH:mm:ss.S’ or ‘yyyy-MM-dd HH:mm:ss’. I would like a clean way to convert them from date strings into an array of date time format.
Example code:
a={‘2016-02-09 10:28:00′;’2016-02-09 10:28:01.5’}
out=datetime(a,’InputFormat’,’yyyy-MM-dd HH:mm:ss.S’,’InputFormat’,’yyyy-MM-dd HH:mm:ss’,’Format’,’yyyy-MM-dd HH:mm:ss.S’);
Actual output:
out =
2016-02-09 10:28:00.0
NaT
Desired output:
out =
2016-02-09 10:28:00.0
2016-02-09 10:28:00.5 I have an output file that has timestamps in the form of ‘yyyy-MM-dd HH:mm:ss.S’ or ‘yyyy-MM-dd HH:mm:ss’. I would like a clean way to convert them from date strings into an array of date time format.
Example code:
a={‘2016-02-09 10:28:00′;’2016-02-09 10:28:01.5’}
out=datetime(a,’InputFormat’,’yyyy-MM-dd HH:mm:ss.S’,’InputFormat’,’yyyy-MM-dd HH:mm:ss’,’Format’,’yyyy-MM-dd HH:mm:ss.S’);
Actual output:
out =
2016-02-09 10:28:00.0
NaT
Desired output:
out =
2016-02-09 10:28:00.0
2016-02-09 10:28:00.5 datetime MATLAB Answers — New Questions