Time series data formatting issues

I have 15 minute interval time series data that is in the format:
MM/dd/yyyy hh:mm:ss a
However at 12:00:00 on each day the time stamp is recorded as
MM/dd/yyyy
with no hh:mm:ss a.
Therefore when I convert it from cell data to datetime, the values for the new day is recorded as a NaN.
How can I get each of the midnight "NaN"'s to record as MM/dd/yyyy hh:mm:ss a?
Thanks

Answers (1)

Clay, the simplest thing to do is just fill in the NaTs after the fact:
>> c
c =
'12/01/2016 10:00:00 PM'
'12/01/2016 11:00:00 PM'
'12/02/2016'
'12/02/2016 01:00:00 AM'
'12/02/2016 02:00:00 AM'
>> d = datetime(c,'Format','MM/dd/yyy hh:mm:ss a')
d =
12/01/2016 10:00:00 PM
12/01/2016 11:00:00 PM
NaT
12/02/2016 01:00:00 AM
12/02/2016 02:00:00 AM
>> d(isnat(d)) = datetime(c(isnat(d)),'Format','MM/dd/yyy')
d =
12/01/2016 10:00:00 PM
12/01/2016 11:00:00 PM
12/02/2016 12:00:00 AM
12/02/2016 01:00:00 AM
12/02/2016 02:00:00 AM
You could also find the "short" strings and append '00:00:00 AM' to them before calling datetime.
Hope this helps.

Categories

Asked:

on 2 Dec 2016

Answered:

on 2 Dec 2016

Community Treasure Hunt

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

Start Hunting!