Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all

Below is my C# code which I translate from VB using some one offline tool but am facing an 'DateDiff' Context error in it

Below is my C# code

C#
if (dateok & timeok)
{
System.DateTime thislesson_datetime = default(System.DateTime);
if (!string.IsNullOrEmpty(Request["form_lesson_time$form_dropdown__Hour"]))
{
thislesson_datetime = Convert.ToDateTime(Request["form_lesson_date"] + " " + Request["form_lesson_time$form_dropdown__Hour"] + ":" + Request["form_lesson_time$form_dropdown__Minute"] + " " + Request["form_lesson_time$form_dropdown__AMPM"]);
}
else
{
thislesson_datetime = Convert.ToDateTime(Request["form_lesson_date"] + " " + Request["form_lesson_time"]);
}
if (DateDiff(DateInterval.Hour, thislesson_datetime, fixed_Now) > 0 & String.Len(String.Trim(Request["form_lesson_notes"])) < 50)
{
errors += "
Please enter detailed lesson notes.";
}
}

Error:
if (DateDiff(DateInterval.Hour, thislesson_datetime, fixed_Now) > 0 & String.Len(String.Trim(Request["form_lesson_notes"])) < 50)
Error Name: The name 'DateDiff' Does not exist in current context.

You all are requested to help me sort this error
Posted
Updated 12-Jun-15 18:43pm
v2

do as below
C#
if ((fixed_Now -thislesson_datetime).TotalHours > 0 && Request["form_lesson_notes"].Trim().Length < 50)
{

}
 
Share this answer
 
v3
Comments
Richard Deeming 12-Jun-15 7:27am    
Close, but the String class doesn't have static methods called Len or Trim. :)
DamithSL 12-Jun-15 23:38pm    
thank you Richard, updated with String.Trim() method and Length property
Boolean AND requires a double ampersand, so:
C#
if (DateDiff(DateInterval.Hour, thislesson_datetime, fixed_Now) > 0 && String.Len(String.Trim(Request["form_lesson_notes"])) < 50)
 
Share this answer
 
Comments
Richard Deeming 12-Jun-15 7:25am    
Technically, you can use a single & / | in a boolean expression, although it's not usually done. They provide non-short-circuiting versions of the more common && / || operators.
Richard MacCutchan 12-Jun-15 8:44am    
Technically ...
Hi ,

you can check like..
C#
if((EndDate - StartDate).TotalDays > 0) 

you will get the date difference.

Thanks
Bimal
 
Share this answer
 
v2

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