Jump to content
MrCheese

Date expiry

Recommended Posts

MrCheese

Hi there,

I'm wanting to put in a line that determines whether the current date is passed the 'expired' date which is included in the code.

I have the idea? But am not overly familiar in determining all the functions in the date.au3 extension.

#include <Date.au3>
Local $expdate = _SetDate(01, 02, 2016)
Local $datediff = _DateDiff('D', $expdate, _NowCalc())
If $datediff = 0 Then
    MsgBox(0, "Expired", "Sorry, this program has expired, contact me for an extension.", 15)
    Exit
EndIf

 

And tried this:

#include <Date.au3>
Local $currdate = _Date_Time_GetSystemTime()
Local $expdate = _SetDate(01, 02, 2015)
If $currdate > $expdate Then
    MsgBox(0, "Expired", "Sorry, this program has expired, contact me for an extension.", 15)

    Exit
EndIf

 

Any assistance would be very appreciated.

 

Thanks

Edited by MrCheese

Share this post


Link to post
Share on other sites
jguinch

_SetDate changes the system date.

You can put the date as string directly in _DateDiff :

#include <Date.au3>

$endDate = "2016/02/01"

Local $datediff = _DateDiff('D', $endDate, _NowCalc() )
If $datediff > 0 Then
    MsgBox(0, "Expired", "Sorry, this program has expired, contact ....@gmail.com for an extension.", 15)
    Exit
EndIf

Note that it is possible do use this :

$endDate = "20160201"
If $endDate < (@YEAR & @MON & @MDAY) Then
    MsgBox(0, "Expired", "Sorry, this program has expired, contact .....@gmail.com for an extension.", 15)
    Exit
EndIf


Edit : sorry, my code was wrong...

Edited by Jos
removed email

Share this post


Link to post
Share on other sites
orbs

it is common that _DateDiff() sees the earlier date first, so better use:

Local $datediff = _DateDiff('D', $expdate, _NowCalc()) ; earlier date first

the above is not mandatory, but it makes more sense, because the diff can be negative. so most important - the condition must be:

If $datediff <= 0 Then

because if it's only = 0 (equals to zero) rather than <= 0 (equals or smaller than zero) then when your users run your program few days after the expiration date, it "becomes" functional again...

this is addressed in the 2nd snippet of the post by @@jguinch (but not the first).

 

and finally, the obvious word of advice - this type of obsolescence method is not very difficult to overcome.

Share this post


Link to post
Share on other sites
MrCheese

Hi guys,

Thank you heaps for your input. I went with this code:

 

$endDate = "20160201"
If $endDate < (@YEAR & @MON & @MDAY) Then
    MsgBox(0, "Expired", "Sorry, this program has expired, contact ....@gmail.com for an extension.", 15)
    Exit
EndIf

Any concerns with that?

Edited by Jos
Removed Email

Share this post


Link to post
Share on other sites
Jos

Code should work, but my only concern would be that you just posted your Email address in your last post which could trigger lots of spam. ;)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

  • Similar Content

    • Siryx
      By Siryx
      So what i need is a function that I pass a starting date into and it counts up to the current date. Example:
      2009-05-30
      2009-05-31
      2009-06-01
      ...
      2018-06-18
      How would I do that? I found the Date.au3 in the includes but I can't find anything close to a time object like I'm used to working with in Java. I just need some $date = setDate(2009-05-30) and from there I could just add a day every time. I need this to be in the very format I stated earlier and from what I can see everytime related to date and time is automatically changed to my german locale.
      €: I already tried setDate but instead it changed my PCs clock. Not quite what i was looking for  
    • nacerbaaziz
      By nacerbaaziz

      Hello
      I have a question please
      How to show Islamic date in Autoit
      I mean
      for example
      Ramadan month
      And moharam month ... etc
      I hope my question is clear for you
      Thanks in advance
    • Jury
      By Jury
      So I get:
      $aMatch[0] Date(1499295600000)   this is supposed to be 06 Jul 2017
      $aMatch[0] Date(1483574400000)  this is supposed to be 05 Jan 2017
      does anybody know the formula to calculate the date from the large number?  It doesn't seem to be anything to do with DateToDayValue.
      thanks in advance.
    • litlmike
      By litlmike
      I am taking a Date & Time and splitting them using _DateTimeSplit, so that I can create a filename in the format: YYYYMMDD_HHMMSS.jpg.  The only issue is that if the month, or day, is a two-digit number that begins with a zero (so less than 10), then the month, or day, is formatted as a single-digit number.  Suggestions on how to accomplish this?
      Example:
      20180101 becomes 2018, 1, 1
      20180303 becomes 2018, 3, 3
      20180505 becomes 2018, 5, 5
      20180606 becomes 2018, 6, 6
      20180909 becomes 2018, 9, 9
      What I want:
      20180101 becomes 2018, 01, 01
      20180303 becomes 2018, 03, 03
      20180505 becomes 2018, 05, 05
      20180606 becomes 2018, 06, 06
      20180909 becomes 2018, 09, 09
      Func _CreateFileNameFromDateTimeFormat($sDateThatWasChangedIntoDateTimeFormat = "2018/01/02 10:29:39") Local $aMyDate, $aMyTime, $sNewImageFileName _DateTimeSplit($sDateThatWasChangedIntoDateTimeFormat, $aMyDate, $aMyTime) _ArrayDisplay($aMyDate) _ArrayDisplay($aMyTime) ;This will become file name $sNewImageFileName = $aMyDate[1] & $aMyDate[2] & $aMyDate[3] & "_" & $aMyTime[1] & $aMyTime[2] & $aMyTime[3] & ".jpg" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sNewImageFileName = ' & $sNewImageFileName & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console EndFunc ;==>_CreateFileNameFromDateTimeFormat  
       
    • Shedunn
      By Shedunn
      I've been looking through some different functions(not sure if that's the right word) to get the Date and time and I can't find one that doesn't include "/ " or ":" in what is returned.

      I'm trying to create a file name with this format "QuickConfig_MMDDYYYY_HHMM"  (doesn't matter if 24 or 12hr format)
      #include <Date.au3> Func _SaveConfig MouseClick('primary',155, 46, 1, 0) ;clicks save as WinWait('Save bluePRINT Configuration As...','', 4) MouseClick('primary',632, 47, 1, 0) ;clicks the file path bar $Documents = @MyDocumentsDir $FilePath = $Documents & '\BP3 Configs' Send($FilePath) Send('{ENTER}') MouseClick('primary',166, 580, 1, 0) ;clicks file name bar $FileName = 'QuickConfig_' & _NowDate & '_' & _NowTime Send($FileName) Send('{ENTER}') EndFunc  
       
      I'm wondering if there is a function somewhere to do this?
×