CLARION日期转换C#+日期添加/减去 [英] CLARION Date Conversion C# + DATE ADD/SUBTRACT

查看:119
本文介绍了CLARION日期转换C#+日期添加/减去的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*(这是针对ISV数据库的,因此我对此进行了反向工程,无法更改)...

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

如何在C#中将以下日期转换为int(维萨/反之亦然)...

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

所以说日期是:

5/17/2012

它被转换为int

77207

在数据库中.

起初我以为这是儒略日期,但事实并非如此.我从 Julian日期问题,但这不匹配.

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

我一直在使用此SQL进行转换:

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

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

,它似乎是正确的.我该如何在C#中进行此转换?有人能启发我这是基于什么标准的,或者仅仅是一个随机转换.预先感谢.

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.

推荐答案

这似乎是

自1800年12月28日以来经过的天数

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

据称,在Excel中显示号召日期仅需

从值中减去36161并将其格式化为日期

subtracting 36161 from the value and formatting it as a date

这篇关于CLARION日期转换C#+日期添加/减去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆