Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLARION Date Conversion C# + DATE ADD/SUBTRACT

Tags:

c#

tsql

clarion

*(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.

like image 537
bumble_bee_tuna Avatar asked May 17 '12 16:05

bumble_bee_tuna


2 Answers

//TO int
var date = new DateTime(1800,12,28,0,0,0);            
var daysSince = (DateTime.Now-date).Days;

//FROM int
var date = new DateTime(1800, 12, 28, 0, 0, 0);
var theDate = date.AddDays(77207);
like image 64
Eric Dahlvang Avatar answered Oct 06 '22 01:10

Eric Dahlvang


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

like image 28
Joshua Drake Avatar answered Oct 06 '22 00:10

Joshua Drake