MATLAB Answers

Date formats 'uuuu' vs 'yyyy', 'mm' vs 'MM'

34 views (last 30 days)
John Taylor
John Taylor on 4 Mar 2021
Commented: John Taylor on 4 Mar 2021
Hello,
Can anyone explain to me when to use "uuuu" for years, upper or lower case for m month?
'dd/mm/yyyy HH:MM'
or
'dd/MM/uuuu HH:mm'
for '14/03/2021 07:30' (14th of March 2021 at 7.30am)
Some functions seem to use one format and others the other one. Every time I try with one, it's the other one.
Is there a certain logic behind this?

Accepted Answer

Adam Danz
Adam Danz on 4 Mar 2021
Edited: Adam Danz on 4 Mar 2021
The confusion is warranted and due to inconsistencies in Matlab's date-time formats.
datetime format uses MM/mm for months/minutes but datestr, datenum, and datevec use mm/MM for months/minutes. A recent comment in the forum highlights how difficult it is to detect the error caused by using the wrong case in datetime values.
Learn about uuuu/yyyy in the documentation.
  • u, uu, etc are ISO years which are negative for BCE years.
  • y, yy, etc are regular years (better term than regular?)
Examples:
datetime('today','format','yyyy-MM-dd G') - years(3000)
ans = datetime
0980-03-04 BCE
datetime('today','format','uuuu-MM-dd G') - years(3000)
ans = datetime
-0979-03-04 BCE
  2 Comments
John Taylor
John Taylor on 4 Mar 2021
Great explaination! thank you so much

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!