# Is there a function that converts DateObjects to decimal years?

**URL:** <https://community.wolfram.com/t/is-there-a-function-that-converts-dateobjects-to-decimal-years/23837>\
**Category:** Questions\
**Tags:** units\
**Created:** [April 5, 2024, 9:28pm UTC](https://community.wolfram.com/t/is-there-a-function-that-converts-dateobjects-to-decimal-years/23837 "2024-04-05T21:28:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirkhackett](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@kirkhackett](https://community.wolfram.com/u/kirkhackett)\
**Post date:** [April 5, 2024, 9:28pm UTC](https://community.wolfram.com/t/is-there-a-function-that-converts-dateobjects-to-decimal-years/23837/1 "2024-04-05T21:28:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![eric3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/eric3/32/12760_2.png) [@eric3](https://community.wolfram.com/u/eric3)\
**Post date:** [April 5, 2024, 10:41pm UTC](https://community.wolfram.com/t/is-there-a-function-that-converts-dateobjects-to-decimal-years/23837/2 "2024-04-05T22:41:58Z")

</div>

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"] *)

```

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [April 6, 2024, 11:25am UTC](https://community.wolfram.com/t/is-there-a-function-that-converts-dateobjects-to-decimal-years/23837/3 "2024-04-06T11:25:29Z")

</div>

Something like this?

```
1900. + AbsoluteTime[Today]/
  QuantityMagnitude[Quantity[1, "Years"], "Seconds"]

```

---

<div class="post-metadata">

**Author:** ![kirkhackett](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@kirkhackett](https://community.wolfram.com/u/kirkhackett)\
**Post date:** [April 6, 2024, 1:46pm UTC](https://community.wolfram.com/t/is-there-a-function-that-converts-dateobjects-to-decimal-years/23837/4 "2024-04-06T13:46:35Z")

</div>

Thanks! I’ll check it out.

---

<div class="post-metadata">

**Author:** ![kirkhackett](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@kirkhackett](https://community.wolfram.com/u/kirkhackett)\
**Post date:** [April 6, 2024, 1:48pm UTC](https://community.wolfram.com/t/is-there-a-function-that-converts-dateobjects-to-decimal-years/23837/5 "2024-04-06T13:48:31Z")

</div>

Thanks, Eric! I appreciate the help.

---

<div class="post-metadata">

**Author:** ![gdelfino](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/gdelfino/32/41294_2.png) [@gdelfino](https://community.wolfram.com/u/gdelfino)\
**Post date:** [April 10, 2024, 4:57pm UTC](https://community.wolfram.com/t/is-there-a-function-that-converts-dateobjects-to-decimal-years/23837/6 "2024-04-10T16:57:48Z")

</div>

Notice that

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

```

This seems better:

```auto
DateValue[{2024,12,31},"Year"] + DateValue[{2024,12,31},"YearFraction"]
(* 2024.95 *)

```
