Message Boards Message Boards

0
|
667 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Is there a function that converts DateObjects to decimal years?

Posted 1 month ago

I have been seeing climate data sets that use decimal years. This is very convenient for some things. Is there a Mathematica function that converts DateObjects to decimal years?

POSTED BY: Kirk Hackett
5 Replies

Something like this?

1900. + AbsoluteTime[Today]/
  QuantityMagnitude[Quantity[1, "Years"], "Seconds"]
POSTED BY: Gianluca Gorni
Posted 1 month ago

Thanks! I’ll check it out.

POSTED BY: Kirk Hackett

Notice that

1900. + AbsoluteTime[{2024,12,31}]/QuantityMagnitude[Quantity[1,"Years"],"Seconds"]
(* 2025.03 *)

This seems better:

DateValue[{2024,12,31},"Year"] + DateValue[{2024,12,31},"YearFraction"]
(* 2024.95 *)
POSTED BY: Gustavo Delfino
Posted 1 month ago

By "decimal years" do you mean something like today (April 5) is 0.26 years from the beginning of the year?

DateDifference[DateObject[{2024, 1}], DateObject[{2024, 4, 5}], "Year"]
(* Quantity[0.25956284153005466, "Years"] *)
POSTED BY: Eric Rimbey
Posted 1 month ago

Thanks, Eric! I appreciate the help.

POSTED BY: Kirk Hackett
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract