Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public string BindDisplayUntil(ref SqlDataReader rs, bool edit)
{
string html = "";

if (edit)
{
html = "<input type=text maxlength=10 class=input size=14 name=display_until_date id=display_until_date";
html += " value=\"" + String.Format(rs["display_until_date"].ToString(), "M/d/yyyy").ToString() + "\">";
html += "";
html += "<img src=\"images/icon-calendar.gif\" align=\"baseline\" alt=\"Show/Hide Calendar\" border=0 width=\"24\" height=\"16\">";
}
else
{
html = "<span"> 0 ? " style=\"color:red;\"" : "") + ">";
html += String.Format(rs["display_until_date"].ToString(), "M/d/yyyy").ToString() + "";
}

return html;
}

I have this C# code when am running this code the following error arises
html = "<span"> 0 ? " style=\"color:red;\"" : "") + ">";
The name 'DateDiff' does not exist is current context.

The 'DateDiff' keyword i need to replace in C#
Posted
Updated 11-Jun-15 23:11pm
v3
Comments
F-ES Sitecore 12-Jun-15 5:12am    
I don't think your code posted properly, there is no mention of DateDiff in it and it looks a little odd.

1 solution

Um...
C#
html = "<span"> 0 ? " style=\"color:red;\"" : "") + ">";

Should that double quote after span be there? I'm not sure exactly what you are trying to do there, because the VB code doesn't look like it should compile either...


Update from OP:

C#
html = "<span" + (DateDiff("d", rs["display_until_date"], Now()) > 0 ? " style=\"color:red;\"" : "") + ">";


Ah!
Simple:
Cast the return value as a DateTime (if you DB has DATETIME or DATE values):
C#
DateTime until (DateTime) rs["display_until_date"];
Or use Parse is you have got it wrong ans store it as a string:
C#
DateTime until = DateTime.Parse(rs["display_until_date"].ToString());
Then:
C#
html = "<span" + (until - DateTime.Now).TotalDays > 0 ? " style=\"color:red;\"" : "") + ">";
 
Share this answer
 
v2
Comments
Ranju_test 12-Jun-15 5:10am    
public string BindDisplayUntil(ref SqlDataReader rs, bool edit)
{
string html = "";

if (edit)
{
html = "<input type=text maxlength=10 class=input size=14 name=display_until_date id=display_until_date";
html += " value=\"" + String.Format(rs["display_until_date"].ToString(), "M/d/yyyy").ToString() + "\">";
html += "";
html += "<img src=\"images/icon-calendar.gif\" align=\"baseline\" alt=\"Show/Hide Calendar\" border=0 width=\"24\" height=\"16\">
";
}
else
{
html = "<span" + (DateDiff("d", rs["display_until_date"], Now()) > 0 ? " style=\"color:red;\"" : "") + ">";
html += String.Format(rs["display_until_date"].ToString(), "M/d/yyyy").ToString() + "</span>";
}

return html;
}

I have this C# code when am running this code the following error arises
html = "<span" + (DateDiff("d", rs["display_until_date"], Now()) > 0 ? " style=\"color:red;\"" : "") + ">";
The name 'DateDiff' does not exist is current context.

The 'DateDiff' keyword i need to replace in C#
OriginalGriff 12-Jun-15 5:29am    
Answer updated

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