date computations in a table

4 visualizzazioni (ultimi 30 giorni)
Danielle Leblance
Danielle Leblance il 1 Giu 2017
Commentato: Andrei Bobrov il 3 Giu 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?

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 1 Giu 2017
Modificato: Andrei Bobrov il 1 Giu 2017
LC.date = datetime(sprintfc('%d',LC.date),'InputFormat','yyyyMMdd');
LC.month_year = [month(LC.date),year(LC.date)]

Più risposte (1)

Peter Perkins
Peter Perkins il 2 Giu 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')

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by