CLARION Date Conversion C# + DATE ADD/SUBTRACT

你离开我真会死。 提交于 2020-01-13 09:27:07

问题


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


回答1:


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




回答2:


//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);



回答3:


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




回答4:


Here is the vb.net Code 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")


来源:https://stackoverflow.com/questions/10639677/clarion-date-conversion-c-sharp-date-add-subtract

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!