| View previous topic :: View next topic |
| Author |
Message |
h4c0r-BG Master Cheater
Reputation: 0
Joined: 29 Nov 2006 Posts: 449 Location: The yogurt country
|
Posted: Sun May 04, 2008 6:37 pm Post subject: [Delphi] Comparing CurrentDate/LicensekeyDate |
|
|
I want to come up with a good algoritm for comparing the current date and the date within the "license key".
It's late right now and it's 05.05.2008.
Here what i've tried so far:
Try one:
| Quote: | | if (day>=21) and (month>=3) and (year>=2008) then showmessage('License expired!') else showmessage('License not expired!'); |
This returns:
| Quote: | License not expired! |
It seems that i messed it up somewhere with the "and" and it doesn't retur the correct value.
I can't think of a good algoritm either... i am sleepy and i thinked of a "something" which i realised that is stupid but here it is:
| Quote: | {if (year>=2009) then showmessage ('License expired! ') else
begin
if (month>=1) then showmessage ('License expired! ') else
begin
if (day>=5) then showmessage('License expired! ') else showmessage('License not expired! ');
end;
end;} |
first line returns false >> skip showmessage and continue
second line returns true >> show message that is expired, BUT GOD .... It's A KEY UNTILL 2009 year.......
Anyway can someone show me a hint about fixing that problem or helping at building that algoritm the right way.... so...
By the way i looked in the net for some tips and tricks about this and i happend to find that: http://delphi.about.com/library/rtl/blrtlCompareDate.htm which didn't really help me.
And here is my current code and declarations:
| Code: | procedure TForm1.Button2Click(Sender: TObject);
var
year,month,day: word;
begin
decodedate(now,year,month,day);
{if (year>=2009) then showmessage ('License expired! :)') else
begin
if (month>=1) then showmessage ('License expired! :)') else
begin
if (day>=5) then showmessage('License expired! :)') else showmessage('License not expired! :(');
end;
end;}
if (day>=21) and (month>=3) and (year>=2008) then showmessage('License expired! :)') else showmessage('License not expired! :(');
end;
end. |
_________________
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sun May 04, 2008 6:43 pm Post subject: |
|
|
Just reverse it.
if(year<=2009) license ok
else if(month<=1) license ok
else if(day <=5)license ok
else license bad
EDIT:
that wouldn't work for some stuff
if(year < 2009) license ok
else if(year > 2009) license bad
else if(month < 1) license ok
else if(month > 1) license bad
else if(day <= 5) license ok
else license bad
_________________
|
|
| Back to top |
|
 |
h4c0r-BG Master Cheater
Reputation: 0
Joined: 29 Nov 2006 Posts: 449 Location: The yogurt country
|
Posted: Sun May 04, 2008 7:02 pm Post subject: |
|
|
HalfPrime, your method doesn't work because:
| Quote: | if (year<2002) then showmessage ('License is ok ') else
begin
if (month<6) then showmessage ('License is ok ') else
begin
if (day<22) then showmessage('License is ok ') else showmessage('License is bad! ');
end;
end; |
Returns:
| Quote: | ('License is ok ') |
Edit:
Haha nice edit of your post.
Edit2:
I will go to sleep i can't think like that. I hope in the morning i will have a fresh mind. I wish you good luck to all of you.
_________________
|
|
| Back to top |
|
 |
|