Converting date into date and hours
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have half hourly energy data and need to convert the date into hourly format. At present the date is dd/mm/yyyy and hour is 0.5,1.0,1.5,... I want to get it as yyyy-mm-dd HH:MM:SS Any idea how to do it??
1 comentario
James Tursa
el 21 de Sept. de 2017
Please be more specific. What is the exact format of your input data (the date and hour data)? Character string array and double array? Cell arrays? Or ...? And what do you want for the result ... a cell array of character strings? Or ...?
Respuestas (1)
Peter Perkins
el 21 de Sept. de 2017
Use datetimes and durations:
>> t0 = datetime('today','Format','yyyy-MM-dd HH:mm:ss')
t0 =
datetime
2017-09-21 00:00:00
>> t = t0 + hours(0:.5:3)'
t =
7×1 datetime array
2017-09-21 00:00:00
2017-09-21 00:30:00
2017-09-21 01:00:00
2017-09-21 01:30:00
2017-09-21 02:00:00
2017-09-21 02:30:00
2017-09-21 03:00:00
0 comentarios
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!