Jump to content

Date control


 Share

Recommended Posts

Hi guys,

 

I have some code; which doesn't quite work.

$dateStop = "11302015"
$tDate = _Date_Time_GetSystemTime()
$currentdatestring = _Date_Time_SystemTimeToDateStr($tDate)

If $currentdatestring >= $dateStop Then
    MsgBox(0, "Expired", "Script has expired.")
    Exit
EndIf

 

Basically, I want to essentially put an expiry date on the script.

 

Where in the example above, it is 30th November 2015.

 

Sometimes it works, sometimes it doesn't. 

I may have the string wrong, I may have the code all wrong.

 

I thought about using the macro @mon @year etc but it gets quite conditional.

i.e. if its 2015, but October, or if its 2015 and Dec, or if its March 2016 etc.

 

But simplicity is great. Any help would be awesome.

 

Link to comment
Share on other sites

May I suggest the YYYY/MM/DD date format to make things easier
Then you could use _DateDiff() , or this

#include <Date.au3>

$dateStop = "2015/11/30"
$dateStopstring = StringReplace($dateStop, "/", "")
; $currentdatestring = StringReplace(_NowCalcDate(), "/", "")
$currentdatestring = @YEAR & @MON & @MDAY

If $currentdatestring >= $dateStopstring Then
    MsgBox(0, "Expired", $currentdatestring & @crlf & $dateStopstring)
    Exit
EndIf

 

Edited by mikell
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...