How to remove the year from a datetime table column
Mostrar comentarios más antiguos
I have a datetime table with
'01-Oct-2014'
'02-Oct-2014'
'03-Oct-2014'
'04-Oct-2014'
'05-Oct-2014'
and I would like to get the same table (or an additional column in that table) but with day-month only for each row
7 comentarios
Dyuman Joshi
el 17 de Sept. de 2023
Movida: Dyuman Joshi
el 20 de Sept. de 2023
Simply change the format of the data -
%Data
y = datetime(["01-Oct-2014";
"02-Oct-2014"
"03-Oct-2014"
"04-Oct-2014"
"05-Oct-2014"])
%Change the format of the datetime array
y.Format = 'dd-MMM';
y
Paul Barrette
el 18 de Sept. de 2023
Movida: Dyuman Joshi
el 20 de Sept. de 2023
Dyuman Joshi
el 18 de Sept. de 2023
Movida: Dyuman Joshi
el 20 de Sept. de 2023
Well, then you will have to get the day and the month data separately and store in a format you want to, as the datetime data type requires year as an input.
So, the question is how do you want store them?
Star Strider
el 18 de Sept. de 2023
Movida: Dyuman Joshi
el 20 de Sept. de 2023
Dyuman Joshi
el 18 de Sept. de 2023
Movida: Dyuman Joshi
el 20 de Sept. de 2023
Yes, I was going to provide that in my comment above, but thought that it would be better to answer after OP provides details on what the expected outcome is.
Paul Barrette
el 18 de Sept. de 2023
Movida: Dyuman Joshi
el 20 de Sept. de 2023
Dyuman Joshi
el 18 de Sept. de 2023
Movida: Dyuman Joshi
el 20 de Sept. de 2023
How about this?
%Data
y = datetime(["01-Oct-2014";
"02-Oct-2014"
"03-Oct-2014"
"04-Oct-2014"
"05-Oct-2014"])
%Get the day
d = day(y)
%Get the month, with the name in short form
m = month(y,'shortname')
%Single Quotation marks gives cell array
%Double Quotation marks gives string array
z = compose("%d-%s", d, string(m))
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Calendar 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!
