How to understand a datenum date?

35 visualizzazioni (ultimi 30 giorni)
Victoria Helm
Victoria Helm il 24 Ago 2021
Commentato: Stephen23 il 25 Ago 2021
I'm trying to write some code that loops through files that are distinguished by date and I want to use the serial dates generated by datenum to do so. However, I'm having trouble understanding how datenum generates the serial date values. For instance, if I execute the following pseudocode:
myPath = 'D:\data\animals'
listing = dir(myPath)
...and if I open the listing I get a struct with one field being the datenum for each file in my directory. I see that the date and time '23-Aug-2021 18:29:25' generates the datenum 7.3839e+05. I don't understand the pattern. How does that date and time generate that exact value?
Thank you!!!
  1 Commento
Stephen23
Stephen23 il 25 Ago 2021
"How does that date and time generate that exact value?"
The DATENUM documentation states: "A serial date number represents the whole and fractional number of days from a fixed, preset date (January 0, 0000) in the proleptic ISO calendar." Thus if you counted all days (including leap days) from day 0 of year 0000 until the 23rd of August 2021, then you will get that serial date number.
Storing dates as a serial number is very common in computing, only the epoch and unit can be very different.

Accedi per commentare.

Risposte (1)

per isakson
per isakson il 24 Ago 2021
Modificato: per isakson il 24 Ago 2021
A serial date (number) represents time as the number of days (and fraction of days) from January 0, 0000.
sdn = now % the function, now, returns a serial date number
sdn = 7.3839e+05
str = datestr( sdn )
str = '24-Aug-2021 22:09:33'
datenum( str )
ans = 7.3839e+05
  1 Commento
Walter Roberson
Walter Roberson il 25 Ago 2021
Right.
Note that if you are doing serious astronomical or historical work, you need to ask yourself:
  • what about leap years?
  • what about leap years before the reformation of what constituted a leap year?
  • what about the time before leap years were a thing at all?
  • What about "the Lost Days" (calendar reform to fix leap year problems), which is something that went into effect in different countries at different times
  • What about leap seconds?
  • solar day or sidereal days?

Accedi per commentare.

Categorie

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

Community Treasure Hunt

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

Start Hunting!

Translated by