MATLAB Answers

Martin
0

Frustrating datetime and datestr

Asked by Martin
on 11 Nov 2018
Latest activity Commented on by Martin
on 11 Nov 2018
Hey I got this
hund = datetime(end_stamp, 'convertfrom','posixtime')
% which give this:
hund =
datetime
05-Nov-2018 00:00:00
Because this one hit time 00:00:00 and I use datestr i get this:
hund = datestr(hund)
hund = '05-Nov-2018'
But I need to get the exact line as a string:
hund = '05-Nov-2018 00:00:00'
Anyone have an idea ?

  0 Comments

Sign in to comment.

Products

2 Answers

Answer by jonas
on 11 Nov 2018
Edited by jonas
on 11 Nov 2018
 Accepted Answer

Not sure why you'd want to convert from datetime to datestr, but here's your solution:
datestr(t,'dd-mmm-yyyy HH:MM:SS')

  0 Comments

Sign in to comment.


Answer by Martin
on 11 Nov 2018

thanks for answer. Let me say whats confusing me. If I use
t = datetime('03-Nov-2018 00:00:00','InputFormat','dd-MMM-yyyy HH:mm:ss');
Here the format is 'dd-MMM-yyyy HH:mm:ss' (the string is input)..
On the other hand with datestr I now use this (thanks jonas)
datestr(t,'dd-mmm-yyyy HH:MM:SS')
the format is 'dd-mmm-yyyy HH:MM:SS'.
Im confused since the format
'dd-MMM-yyyy HH:mm:ss' ~= 'dd-mmm-yyyy HH:MM:SS'

  2 Comments

jonas
on 11 Nov 2018
I don't know if there is a reason, but the format differs depending on function. In datetime the month is capital letters and in datestr they are not. It is described in the documentation, but I don't know the reason for this.
Martin
on 11 Nov 2018
yeah okay, a bit strange in my opinion. Anyway, now it works thanks to you :)

Sign in to comment.