date computations in a table

1 visualización (últimos 30 días)
Danielle Leblance
Danielle Leblance el 1 de Jun. de 2017
Comentada: Andrei Bobrov el 3 de Jun. de 2017
I have a table LC that has a column of dates called "date". The date format is however 19850331. I want to extract the year and the month of this date. How can I do so?

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 1 de Jun. de 2017
Editada: Andrei Bobrov el 1 de Jun. de 2017
LC.date = datetime(sprintfc('%d',LC.date),'InputFormat','yyyyMMdd');
LC.month_year = [month(LC.date),year(LC.date)]

Más respuestas (1)

Peter Perkins
Peter Perkins el 2 de Jun. de 2017
Andrei provided the right answer if those data are text, e.g. '19850331' or "19850331". If they are numeric, use
datetime(LC.Date,'ConvertFrom','yyyymmdd')

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by