Click here to Skip to main content
15,905,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All

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

C#
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
Posted
Updated 15-Jun-15 0:10am
v3
Comments
Tomas Takac 15-Jun-15 6:13am    
This is your third question re DateDiff in C#. You even accepted on of the previous solutions. So would you care to explain what's different this time? Otherwise it's a clear re-post.

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[^]
 
Share this answer
 
Comments
Ranju_test 15-Jun-15 6:25am    
Can you please suggest how this TimeSpan could be used
F-ES Sitecore 15-Jun-15 6:46am    
Click the link and there are examples at the bottom of the page.
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
 
Share this answer
 
C#
//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;
                }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900