Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi any body tell me....i have fromdate and todate in front end and database table have date 10/6/2011 and 11/6/2011
example from date-9/6/2011

9/6/2011-absent
todate -12/6/2011 i enter show 10/6/2011 present
and 11/6/2011 present
12/6/2011-absent.........i already display present using databind but how can i check remaining date its absent
Posted
Comments
Sergey Alexandrovich Kryukov 10-Jun-11 14:24pm    
Explain more clearly. What's the language?
--SA

1 solution

A date cannot be "remaining". Remaining can be the time span, for example from the current time to some stated date such as deadline. Here is how can it look in C#:

C#
int RemainingDays(System.DateTime setTime) { //setTime is from your data base
    System.TimeSpan span = System.DateTime.Now - setTime;
    return span.Days; //can be negative if overdue
}


If you need to get time from the date represented as string, read about the following methods:

  • System.DateTime.Parse(string);
  • System.DateTime.Parse(String, IFormatProvider, DateTimeStyles);
  • System.DateTime.ParseExact(String, String, IFormatProvider); (you can use System.Globalization.CultureInfo as IFormatProvider);
  • System.DateTime.ParseExact(String, String, IFormatProvider, DateTimeStyles);
  • System.DateTime.ParseExact(String, String[], IFormatProvider, DateTimeStyles)

See:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA
 
Share this answer
 
v2
Comments
Abhinav S 10-Jun-11 14:33pm    
Super answer! 5.
Sergey Alexandrovich Kryukov 10-Jun-11 14:35pm    
Big deal...
Thank you, Abhinav.
--SA

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