Effacer les filtres
Effacer les filtres

Converting Numeric Dates in Matlab does not work

2 vues (au cours des 30 derniers jours)
Metin Akyol
Metin Akyol le 3 Mar 2022
I have a date column in my table with dates in numeric format, e.g. one date might look like this: 738570
When I try to convert it like this:
table1.Date = date(table1.Date)
I get this error:
Error using date Too many input arguments
  2 commentaires
Stephen23
Stephen23 le 3 Mar 2022
The DATE function does not accept any input arguments:
What do you expect to happen when you call a function with more input arguments than it accepts?
Metin Akyol
Metin Akyol le 3 Mar 2022
Makes sense. I ended up trying that after I got this error with Datetime:
Numeric Input data must be a matrix with three or six columns ....

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 3 Mar 2022
Modifié(e) : KSSV le 3 Mar 2022
table1.Date = datestr(table1.Date)
Or
table1.Date = datetime(datevec(table1.Date))
  1 commentaire
Metin Akyol
Metin Akyol le 3 Mar 2022
datestr worked!! Thank you so much.

Connectez-vous pour commenter.

Plus de réponses (1)

Steven Lord
Steven Lord le 3 Mar 2022
Another way to do this is to convery the serial date number to a datetime using the 'ConvertFrom' name-value pair argument.
x = 738570;
dt = datetime(x, 'ConvertFrom', 'datenum')
dt = datetime
18-Feb-2022
Let's check, since a datenum is the "Number of days since 0-Jan-0000 (proleptic ISO calendar)."
check = datetime(0, 1, 0) + caldays(x) % x calendar days after 0-Jan-0000
check = datetime
18-Feb-2022

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by