MATLAB: How to shift date-time variable to a common start-date/time

chardatedatetimeMATLABshifttimetimeshift

I have some data formatted as follows:
% Simple example as the "actual_dates" is a large char array.
common_date = datetime(14,1,1,0,0,0) % Define a common start date (01-Jan-0014 00:00:00)
actual_dates = '29-Jan-2014 13:57:30' % This is "char"
Then I run this:
t_diff = actual_dates - common_date % The shift value
and get this weird result:
t_diff = 17532325:57:35
The end goal is to have this:
shifted_date = actual_dates - t_diff
For this particular example, want to have shifted_date = '01-Jan-0014 00:00:00'
How can I fix this? I'm not sure how to convert the 'char' array into a datetime format.

Best Answer

I don’t understand what you want to do, but converting the string to a datetime object is srtaightforward. Doing calculations on them is a bit more involved, since it requires the appropriate functions.
Try this to start:
common_date = datetime(14,1,1,0,0,0);
actual_dates = '29-Jan-2014 13:57:30';
act_date = datetime(actual_dates);
t_diff = between(common_date,act_date)
produces:
t_diff =
2000y 28d 13h 57m 30s