Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am retrieving two dates from database in format 31-Dec-14 , DataFormatString="{0:dd-MMM-yy}" , i am retrieving it in a label


I want that if the date is ahead of todays date the second label should appear as date excedded...

Can someone please help me
Posted
Comments
Thanks7872 11-Dec-14 1:51am    
What is the type of the date you get out of DB? DateTime or string?

If you are using c# you can convert the dates in string format to the DateTime[^] type.

Example:
C#
string dateString1 = "31-Dec-14";
string dateString2 = "5-Jan-15";

DateTime date1 = DateTime.ParseExact(dateString1, "dd-MMM-yy", null);
DateTime date2 = DateTime.ParseExact(dateString2, "dd-MMM-yy", null);
TimeSpan diff = date2 - date1;

if (diff.TotalDays > 5) // Or what ever your limit is
    DoSomeStuff();
 
Share this answer
 
v2
Comments
Faisalabadians 11-Dec-14 2:26am    
+5 must be the answer. but it seems like the questioner is a student
George Jonsson 11-Dec-14 2:35am    
Thanks.
One can only hope it is a student. :)
convert the date to DateTime format that you are retrieving in a label.
C#
DateTime dt = Label1.text;
DateTime dt1 = DateTime.Now.Today.ToShortDatString();
if(dt > dt1)
{
//Show your message here
}
 
Share this answer
 
convert Date Into Date and Time

C#
if (Convert.ToDateTime("31/12/2014") <= Convert.ToDateTime(DateTime.Now))
           {
            // Set Your  Message
           }
 
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