Click here to Skip to main content
15,919,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have tried No.of days as mentioned below in load

but i want my application should close after 365 days and msgbox should show renewal and close the applications

1. Every days should reduce the date from date of installation
2. after 365 days should warn about the validtity

Please help me

What I have tried:

Dim firstDate As Date
       Dim SecondDate As Date



       firstDate = Now
       SecondDate = "2021-03-14"

       Label1.Text = DateDiff(DateInterval.Day, firstDate, SecondDate)
Posted
Updated 13-Mar-20 6:32am
v2
Comments
Richard MacCutchan 13-Mar-20 10:36am    
All you need is the difference between date of installation (wherever you store that) and DateTime.Now. If that is more than the maximum period allowed then stop the program.
Member 14621280 13-Mar-20 10:40am    
first date would be the date of installation
Richard MacCutchan 13-Mar-20 12:00pm    
That is what I said. But your code has it the other way round, and assumes that the application will run out of time on 14th March 2021.

1 solution

This is (logically) what you need:
C#
// year, month and day values from your licence key
DateTime date1 = new DateTime(year, month, day);
Console.WriteLine("Application installation date: {0}", date1.ToString("dd MMMM yyyy"));

DateTime date2  = DateTime.Now;
Console.WriteLine("Current date: {0}", date2.ToString("dd MMMM yyyy"));
TimeSpan interval = date2 - date1;
Console.WriteLine("Application has been installed for: {0} days", interval.Days);
if (interval.Days > 365)
{
    Console.WriteLine("Your licence has expired, please contact Customer Services");
    throw new Exception("Expired licence");
}
 
Share this answer
 
Comments
Member 14621280 14-Mar-20 4:00am    
Thanks for reply...But I want to show my lable in main form... Total days
Richard MacCutchan 14-Mar-20 5:05am    
Then modify my samples to pass the strings to the TextBox or Label. Surely you can mange that by yourself.

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