在C#中使用DateDiff方法 [英] DateDiff method use in C#

查看:140
本文介绍了在C#中使用DateDiff方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All



运行以下C#代码.........并面临错误....



Hello All

am running the below C# code.........and facing an error....

if ((DateDiff("d", rs["Date"], DateTime.Now) < 0 & billing_total_today_flag == false))
                {
                    billing_total_today = billing_total;
                    billing_total_today_flag = true;
                }

Error:
if ((DateDiff("d", rs["Date"], DateTime.Now) < 0 & billing_total_today_flag == false))
Error Name:
The name 'DateDiff' does not exists in current context.



所有人都被请求帮助我排序......



谢谢


You all are requested to help me to sort it out...

Thanks

推荐答案

DateDiff因为你试图使用它是一个SQL函数。在c#中,你减去获得TimeSpan对象的兴趣日期,TimeSpan让你知道天数的差异



https://msdn.microsoft.com/en-us/library/system.timespan(v = vs.110 ).aspx [ ^ ]
DateDiff as you are trying to use it is a SQL function. In c# you subtract the dates of interest to get a TimeSpan object, and that TimeSpan lets you know the difference in days

https://msdn.microsoft.com/en-us/library/system.timespan(v=vs.110).aspx[^]


答案与您的问题相同在VB中使用C#中的WriteHtmlResponse方法 [ ^ ]



DateDiff不是.Net中的系统函数



您也必须在c#中编写此功能。



一旦您满意,请接受解决方案与th回答
The answer is the same as in your question Use of WriteHtmlResponse method in C# from VB[^]

DateDiff is not a system function in .Net

You will have to write this function in c# too.

Please accept the solutions once you are satisfied with the answer


//corrected code
if ((Convert.ToDateTime("rs["Date"]") - DateTime.Now).Days < 0 & billing_total_today_flag == false))
                {
                    billing_total_today = billing_total;
                    billing_total_today_flag = true;
                }


这篇关于在C#中使用DateDiff方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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