Search code examples
c#t-sqlclarion

CLARION Date Conversion C# + DATE ADD/SUBTRACT


*(This is for ISV database so I am kind of reverse engineering this and cannot change) ...

How can I do the following date to int (visa/versa) conversion in C# ...

So Say the Date is:

5/17/2012

it gets converted to int

77207

in the database.

At first I thought this was a Julian date however it does not appear to be the case. I was fooling around with the method from Julian Date Question however this does not match up.

   var date = ConvertToJulian(Convert.ToDateTime("5/17/2012"));
   Console.WriteLine(date);

    public static long ConvertToJulian(DateTime Date)
    {
        int Month = Date.Month;
        int Day = Date.Day;
        int Year = Date.Year;

        if (Month < 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;
    }

Outputs 2456055 //Should be 77207

I've been using this SQL to do the conversion:

SELECT Convert(date, CONVERT(CHAR,DATEADD(D, 77207, '1800-12-28'),101))

and it appears to be accurate. How could I do this conversion in C# ? And can someone edify me as to what standard this is based on or is it simply a random conversion. Thanks in advance.


Solution

  • This appears to be a Clarion Date:

    the number of days that have elapsed since December 28, 1800

    Allegedly to, Display Clarion Dates In Excel it only takes

    subtracting 36161 from the value and formatting it as a date