Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.18/5 (3 votes)
See more:
I have a Table Which have 4 Columns.
Table Name- Personnel Details
Fields- Name, Position, Commence Date and Expiry Date.
What I want to make is before 1 month date for expiration which is based on Expiry Date there will be notice or pop up message "To be renew". I don't know how to calculate the date. Thanks..
Posted
Updated 12-Jun-22 6:45am
Comments
Richard MacCutchan 18-Feb-14 10:36am    
TimeSpan t = ExpiryDate - DateTime.Now;
if (t.days < 32)
send the message ...
Member 12628849 20-Aug-16 3:48am    
FFF
Member 12628849 20-Aug-16 7:47am    
I want to make is before 1 month date for expiration which is based on Expiry Date there will be notice or pop up message "To be renew". I don't know how to calculate the date

As long as Expiry Date is a DateTime object, you should have relatively little trouble. Now, I'm assuming here that you are applying this at the client side, seeing that you haven't included SQL Server or other database in your tags, I'm not going to cover doing this as a query and I'm assuming that you have retrieved this data already. Suppose you mapped Expiry Date into a C# property called ExpiryDate, then all you need to do is:
C#
bool shouldRenew = ExpiryDate.AddMonths(-1) > DateTime.Now;
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Feb-14 14:46pm    
Sure, a 5.
—SA
Member 12628849 20-Aug-16 7:45am    
i want to alert before one months date of expiry
This can be achieved by date difference.
See a very good article[^] is given there.

or rather,
C#
DateTime x1 = DateTime.ParseExact("20119", "yyyyM", CultureInfo.InvariantCulture);
DateTime x2 = DateTime.ParseExact("20135", "yyyyM", CultureInfo.InvariantCulture);

int months =  Math.Abs((x2.Month - x1.Month) + 12 * (x2.Year - x1.Year));

-KR
 
Share this answer
 
Comments
Member 12628849 20-Aug-16 7:45am    
i want to show notification for expiry date...this date from database in c#

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