# convert double to date ?

**URL:** <https://discussions.unity.com/t/convert-double-to-date/663627>\
**Category:** Scripting\
**Tags:** Scripting\
**Created:** [May 4, 2017, 9:36am UTC](https://discussions.unity.com/t/convert-double-to-date/663627 "2017-05-04T09:36:04Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![vistriter](https://avatars.discourse-cdn.com/v4/letter/v/e19adc/32.png) [@vistriter](https://discussions.unity.com/u/vistriter)\
**Post date:** [May 4, 2017, 9:36am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/1 "2017-05-04T09:36:04Z")

</div>

![](https://europe1.discourse-cdn.com/unity/original/4X/5/e/2/5e2d2775b483ac9dfaa21682c28a762e8df45a54.png)

 ![](https://europe1.discourse-cdn.com/unity/original/4X/4/c/b/4cbb3603ed88375c842ae1a8f3857fb7ba1ad035.png)

How to fix this ?

---

<div class="post-metadata">

**Author:** ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)\
**Post date:** [May 4, 2017, 9:40am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/2 "2017-05-04T09:40:44Z")

</div>

Here is a list of the constructors available to create a DateTime structure:

> **[DateTime Struct (System)](https://learn.microsoft.com/en-us/dotnet/api/system.datetime?view=net-9.0&redirectedfrom=MSDN)**
>
> Represents an instant in time, typically expressed as a date and time of day.

---

<div class="post-metadata">

**Author:** ![vistriter](https://avatars.discourse-cdn.com/v4/letter/v/e19adc/32.png) [@vistriter](https://discussions.unity.com/u/vistriter)\
**Post date:** [May 4, 2017, 10:26am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/3 "2017-05-04T10:26:13Z")

</div>

I think it’s not relate this error.

---

<div class="post-metadata">

**Author:** ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)\
**Post date:** [May 4, 2017, 10:34am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/4 "2017-05-04T10:34:06Z")

</div>

Okay, you think the error about the parameter in the constructor isn’t related to the constructor of the structure? ☹  
Did you open the page that I linked?

---

<div class="post-metadata">

**Author:** ![vistriter](https://avatars.discourse-cdn.com/v4/letter/v/e19adc/32.png) [@vistriter](https://discussions.unity.com/u/vistriter)\
**Post date:** [May 4, 2017, 10:36am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/5 "2017-05-04T10:36:20Z")

</div>

I use DateTime.FromOADate. But It’s can’t covert.

---

<div class="post-metadata">

**Author:** ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)\
**Post date:** [May 4, 2017, 10:40am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/6 "2017-05-04T10:40:53Z")

</div>

I see… I partially misread that there; that AODate wasn’t posted.  
So, if you Debug.Log the value of ‘d’ what do you get?

---

<div class="post-metadata">

**Author:** ![vistriter](https://avatars.discourse-cdn.com/v4/letter/v/e19adc/32.png) [@vistriter](https://discussions.unity.com/u/vistriter)\
**Post date:** [May 4, 2017, 10:45am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/7 "2017-05-04T10:45:34Z")

</div>

It’s double value. I get this from TimeCheatingDetector.GetOnlineTime(“[pool.ntp.org](http://pool.ntp.org)”);/

d = 3702883471158.15;

---

<div class="post-metadata">

**Author:** ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)\
**Post date:** [May 4, 2017, 10:48am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/8 "2017-05-04T10:48:17Z")

</div>

Dunno that is odd, then. Where is this OADate method? Does it throw exceptions at all ?

---

<div class="post-metadata">

**Author:** ![vistriter](https://avatars.discourse-cdn.com/v4/letter/v/e19adc/32.png) [@vistriter](https://discussions.unity.com/u/vistriter)\
**Post date:** [May 4, 2017, 10:52am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/9 "2017-05-04T10:52:32Z")

</div>

I read from this link. Below here.

[http://stackoverflow.com/questions/13919641/how-to-convert-a-double-value-to-a-datetime-in-c](http://stackoverflow.com/questions/13919641/how-to-convert-a-double-value-to-a-datetime-in-c)

---

<div class="post-metadata">

**Author:** ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)\
**Post date:** [May 4, 2017, 11:05am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/10 "2017-05-04T11:05:45Z")

</div>

lol Okay, I didn’t know about that function.. Cool 🙂  
Now, you didn’t read this completely, I don’t think?

> **[DateTime.ToOADate Method (System)](https://learn.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/x2k67kb6(v=vs.95)?redirectedfrom=MSDN)**

Pasting important remarks:  
**Remarks**  
An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.

The base OLE Automation date is midnight, 30 December 1899. The minimum OLE Automation date is midnight, 1 January 0100. The maximum OLE Automation date is the same as [MaxValue](https://msdn.microsoft.com/en-us/library/system.datetime.maxvalue%28v=vs.95%29.aspx), the last moment of 31 December 9999.

The ToOADate method throws an [OverflowException](https://msdn.microsoft.com/en-us/library/system.overflowexception%28v=vs.95%29.aspx) if the current instance represents a date that is later than [MinValue](https://msdn.microsoft.com/en-us/library/system.datetime.minvalue%28v=vs.95%29.aspx) and earlier than midnight on January1, 0100. However, if the value of the current instance is [MinValue](https://msdn.microsoft.com/en-us/library/system.datetime.minvalue%28v=vs.95%29.aspx), the method returns 0.

---

<div class="post-metadata">

**Author:** ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)\
**Post date:** [May 4, 2017, 11:10am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/11 "2017-05-04T11:10:45Z")

</div>

There is DateTime.ToOADate and From… so, not sure if you used 'ToADate" previously or not.  
This is from the “FromOADate” remarks:

The d parameter is a double-precision floating-point number that represents a date as the number of days before or after the base date, midnight, 30 December 1899. The sign and integral part of d encode the date as a positive or negative day displacement from 30 December 1899, and the absolute value of the fractional part of d encodes the time of day as a fraction of a day displacement from midnight. d must be a value between negative 657435.0 through positive 2958466.0.

Yours, as you can see, was far outside that range.

---

<div class="post-metadata">

**Author:** ![vistriter](https://avatars.discourse-cdn.com/v4/letter/v/e19adc/32.png) [@vistriter](https://discussions.unity.com/u/vistriter)\
**Post date:** [May 4, 2017, 11:44am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/12 "2017-05-04T11:44:40Z")

</div>

Thank you very much! I will to check it. 🙂

---

<div class="post-metadata">

**Author:** ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)\
**Post date:** [May 4, 2017, 11:45am UTC](https://discussions.unity.com/t/convert-double-to-date/663627/13 "2017-05-04T11:45:57Z")

</div>

no problem 🙂 Good luck 🙂
