IF statement and time display

Dear All
I have a string which displays time and date taken from a txt file using:
str= datestr(datenum([yy mm dd HH MM SS]),0);
output yy =
96
96
96
97
98
99
00
01
I want it to be displayed as 1996 if it is before 2000 and 2000,2001,2002,..so on if after 2000.
Also the 'mm' format being displayed is like Jan,feb,.. can it be displayed as 01,02,03,..12? I couldn't find the proper formatting for it.
Current output example: str = 20-Dec-0003 22:47:39
Thanks

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 26 de Sept. de 2012
Editada: Andrei Bobrov el 26 de Sept. de 2012

0 votos

x= {'96318.74847837'
'96319.62211352'
'96319.62351606'
'96319.62356237'
'96320.05952563'
'96320.49676119'} % initial array
a = str2double(x);
y = fix(a/1000);
ymdhms = datevec(datenum(y,0,a - y*1000)); % corrected
[yearnow,~] = datevec(now);
ymdhms(:,1) = (ymdhms(:,1) <= rem(yearnow,2000))*100 + 1900 + ymdhms(:,1);
out = datestr(ymdhms,'yyyy-mm-dd HH:MM:SS');

5 comentarios

Andrei Bobrov
Andrei Bobrov el 26 de Sept. de 2012
correct
Hamza
Hamza el 26 de Sept. de 2012
having an error
Undefined function 'year' for input arguments of type 'double'.
Error in getTLE (line 40) ymdhms(:,1) = (ymdhms(:,1) <= rem(year(now),2000))*100 + 1900 + ymdhms(:,1);
Hamza
Hamza el 26 de Sept. de 2012
also tried using 'y' instead of 'year' but still its not working.
Andrei Bobrov
Andrei Bobrov el 26 de Sept. de 2012
Hi Hamza! Excuse me, I use year as function from the Financial Toolbox. Corrected.
Hamza
Hamza el 27 de Sept. de 2012
Editada: Hamza el 27 de Sept. de 2012
Hey Andrei
It works great now...Thanks a lot!!
I have one last step to cover..can you help?
I will post another question for that.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Sept. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by