I have a database which displays dates as dd/mm/yyyy In my listview I have changed it so it displays as mm/dd/yyyy
<asp:Label ID="TPTIMEIN" runat="Server" Text='<%#Eval("TPTIMEIN", "{0: MM/dd/yyyy HH:mm:ss}") %>' />
I have another part of code which changes the font color to red if the date is more than 2 hours old
Label TimeLabel = (Label)e.Item.FindControl("TPTIMEIN");
if (TimeLabel != null)
{
DateTime Total;
if (DateTime.TryParse(TimeLabel.Text, out Total) == true)
{
if (Total < DateTime.Now.AddHours(-2))
{
TimeLabel.ForeColor = System.Drawing.Color.Red;
}
}
}
However, here's the problem the code above only seems to work on the old format dd/mm/yyyy. So it will highlight 01/11/yyyy but not 01/14/yyyy as it's not recognizing it. How would i change this?
Hope this makes sense.....
Edit
I've tried something like this but I can't use a "<" this way
if (Total < DateTime.Now.AddHours(-2).ToString("MM.dd.yyyy"))