Filter löschen
Filter löschen

build YYYYMMDD instead of YYYYMD, for YY and DD derived from one-digit outputs from datevec()

1 Ansicht (letzte 30 Tage)
Hello. I would like to produce a date (for instance: 7th of January 2014) string looking like '20140107' for representing YYYYMMDD, but a one digit M and D currently results in the unwanted string '201417', which is only YYYYMD.
[Y, M, D, H, MN, S] = datevec(now);
dateString =[num2str(Y),num2str(M),num2str(D)];
Any idea how to get YYYYMMDD always as a 8 digit string, something which is simpler than this?

Akzeptierte Antwort

Phillip
Phillip am 30 Apr. 2014
Hi
dateString = datestr(now,'yyyymmdd')
Type
help datestr
to get more information
Regards, Phillip

Weitere Antworten (1)

Mischa Kim
Mischa Kim am 30 Apr. 2014
Bearbeitet: Mischa Kim am 30 Apr. 2014
Marco, how about
dateString = datestr(now,'yyyymmdd');
  2 Kommentare
Marco
Marco am 30 Apr. 2014
Mischa. thanks!!!! I will give credits to Philip, though. He seems to be new in the forum and as he also answered within seconds, like you, I´ll motivate him to stay with us! Thanks again!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming 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!

Translated by