Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert DateTime to Julian Date in C# (ToOADate Safe?)
    primarykey
    data
    text
    <p>I need to convert from a standard <strong>Gregorian</strong> date to a <strong>Julian</strong> day number. </p> <p>I've seen nothing documented in C# to do this directly, but I have found many posts (while Googling) suggesting the use of <a href="http://msdn.microsoft.com/en-us/library/system.datetime.tooadate.aspx" rel="noreferrer">ToOADate</a>.</p> <p>The documentation on <a href="http://msdn.microsoft.com/en-us/library/system.datetime.tooadate.aspx" rel="noreferrer">ToOADate</a> does not suggest this as a valid conversion method for Julian dates. </p> <p>Can anyone clarify if this function will perform conversion accurately, or perhaps a more appropriate method to convert DateTime to a Julian formatted string.</p> <hr> <p><a href="http://forums.asp.net/p/1173999/1972455.aspx" rel="noreferrer">This</a> provides me with the expected number when validated against <a href="http://en.wikipedia.org/wiki/Julian_day" rel="noreferrer">Wikipedia's Julian Day page</a></p> <pre><code>public static long ConvertToJulian(DateTime Date) { int Month = Date.Month; int Day = Date.Day; int Year = Date.Year; if (Month &lt; 3) { Month = Month + 12; Year = Year - 1; } long JulianDay = Day + (153 * Month - 457) / 5 + 365 * Year + (Year / 4) - (Year / 100) + (Year / 400) + 1721119; return JulianDay; } </code></pre> <p>However, this is without an understanding of the magic numbers being used.</p> <p>Thanks</p> <hr> <p><strong>References:</strong></p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/system.datetime.tooadate.aspx" rel="noreferrer">DateTime.ToOADate Method</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload