CLARION Date Conversion C # + DATE ADD / SUBTRACT

* (This is for the ISV database, so I'm kind of reverse engineering this and can't change) ...

How can I make the following date for converting int (visa / versa) to C # ...

So give the following:

5/17/2012

it is converted to int

77207

in the database.

At first I thought it was a Julian date, but it seems that it is not. I cheated on the Julian Date Question method , however this does not match.
   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 use this SQL to convert:

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

and that seems accurate. How can I do this conversion in C #? And can someone direct me to what standard it is based on, or is it just a random conversion. Thanks in advance.

+5
source share
4 answers

Clarion Date:

, 28 1800 .

, Clarion Excel

36161

+5
//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);
+4

If it is a linear formula, you should be able to calculate the formula in the form y = mx + b. You will need at least two data points.

0
source

Here is the vb.net code that I use to convert Clarion date to Julian Date:

 Dim ldblDaysToSubtract As Double = 36161.0

 mclsRevEmployeeRecd.BirthDate(istrBirthDate:=(CDbl(E1Row.Item("BIRTH_DT")) - ldblDaysToSubtract).ToString)

 mstrBirthDate = Format(CDate(Date.FromOADate(CDbl(istrBirthDate)).ToString), "MM/dd/yyyy")
0
source

All Articles