Why does my datestr return weird result?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am experiencing some problem returning the correct results for my datestr function. When I execute the following script inside the command window:
datestr('18/10/2011 5:05:55 PM','dd/mm/yyyy HH:MM:SS PM')
the output came out as: 02/04/0024 5:05:55 PM
When I execute the following:
datestr('10/18/2011 5:05:55 PM','dd/mm/yyyy HH:MM:SS PM')
the output came out as: 18/10/2011 5:05:55 PM
Is is something to do with my Matlab setting? Basically I want to convert the given string (a time format written as string in dd/mm/yyyy HH:MM:SS pm) into Matlab datestr in dd/mm/yyyy HH:MM:SS pm format
Thanks in advance, Nu'man.
0 Kommentare
Akzeptierte Antwort
the cyclist
am 15 Dez. 2011
When doing string-to-string date conversion, MATLAB assumes that the first input is in "MATLAB standard dateform", which will be mm/dd/yyyy etc. If you want to use a different dateform, you must first convert that to MATLAB standard dateform (using datenum), then convert it back using datestr.
Your second example is in standard dateform, and is correctly converted; your first is not (because it is in dd/mm/yyyy).
This is stated in the "Tips" section of "doc datestr", and in the last paragraph of "help datestr".
Weitere Antworten (2)
Jan
am 15 Dez. 2011
Sorry, I do not get the point. You have a string in the format:
dd/mm/yyyy HH:MM:SS pm
and want to get a string in the format:
dd/mm/yyyy HH:MM:SS pm
???
0 Kommentare
Siehe auch
Kategorien
Mehr zu Financial Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!