Not expected results using datevec funcion

Dear colleagues,
I am writing from Brazil in order to get some help about datavec funciton.
I am using this fucntion to convert a date string data to vector format ([yy mm dd HH MM SS])
In Brazil date format is defined as follows: dd/mm/yy. I have a set of date data in two main formats. one without timestamp and another with timestamp, for instance: '13/12/2013' , '13/12/2013 00:15:00', respectively.
I get an error when I call the function to get the conversion:
Situation 1) result = datevec('13/12/2013', 'dd/mm/yyyy HH:MM:SS');
When I use the function with data with timestamp, as follows
Situation 2) result = datevec('13/12/2013 00:00:00', 'dd/mm/yyyy HH:MM:SS');
or
Situation 3) result = datevec('13/12/2013 00:15:00', 'dd/mm/yyyy HH:MM:SS');
I get correct answer:
Anybody has some hint to handle situation 1?
I appreciate any help. Thanks all in advance.
Best regards, Luis.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 17 de En. de 2014
Editada: Azzi Abdelmalek el 17 de En. de 2014
Use this
result = datevec(datestr('13/12/2013', 'dd/mm/yyyy HH:MM:SS'))
datestr will set the missed time to 00:00:00

5 comentarios

Azzi, thank you for your rapid reply.
However, the command you have recommended results " >> result = datevec(datestr('13/12/2013', 'dd/mm/yyyy HH:MM:SS'))
result =
19 5 6 0 0 0
>> "
an answer that not match with the expected result: [2013 12 13 0 0 0] which is the desired answer.
Anyway, I thank you again for your atention. See ya, mate.
Try this
d={'13/12/2013','26/12/2013 19:20:05'}
dd=cellfun(@(x) [x ' 00:00:00'],d,'un',0)
out=datevec(dd,'dd/mm/yyyy HH:MM:SS')
Luis Fernando
Luis Fernando el 18 de En. de 2014
Azzi, it works as a charm! Thank you for your help, my friend. It is gonna help a lot! Have a good night or day! :-)
Instead of the slow and complicated cellfun method to join strings, strcat is niocer and faster:
dd = strcat(d, ' 00:00:00')
Jan,
Good hint as well! Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Etiquetas

Preguntada:

el 17 de En. de 2014

Comentada:

el 18 de En. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by