How do I convert dates to days?
Mostrar comentarios más antiguos
Let us say I have a series of dates: '01-01-2022', '05-01-2022', '06-01-2022' and I have corresponding data on these dates how do i convert the dates to an array that looks like this: [0,4,5]
Generally something like this:
Respuesta aceptada
Más respuestas (2)
Your example and explanation are inconsistent: your explanation shows difference between adjacent dates, your example vector shows differences to the first date. Here are both:
C = {'01-01-2022', '05-01-2022', '06-01-2022'};
T = datetime(C,'inputFormat','d-M-u');
V = days(T-T(1)) % what your example shows
D = [0,caldays(caldiff(T))] % what you explained
KSSV
el 18 de Mzo. de 2022
0 votos
Read about datevec. This will give you respective days from the dates.
3 comentarios
Hamza Yusuf
el 18 de Mzo. de 2022
DateString = {'09/16/2007';'05/14/1996';'11/29/2010'};
formatIn = 'mm/dd/yyyy';
[y,m,d,H,M,S] = datevec(DateString,formatIn);
d
Hamza Yusuf
el 18 de Mzo. de 2022
Categorías
Más información sobre Time Series Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!