kelp7
(Starting to like KiXtart)
2009-05-14 02:45 PM
Date checking

Hi,

Is it quite easy in a script to check if the current date is one month greater than a date variable set in the script? Are there any easy solutions to that before i reinvent the wheel?

Thanks


kelp7
(Starting to like KiXtart)
2009-05-14 03:13 PM
Re: Date checking

It's okay i've done it now with the following:


break on

$Day_Loan_Given = "13"

$Month_Loan_Given = "4"

$Current_Date = @DATE

$Current_Day = VAL(SUBSTR($Current_Date, 9, 2))

$Current_Month = VAL(SUBSTR($Current_Date, 6, 2))

IF $Current_Month > $Month_Loan_Given and $Current_Day > $Day_Loan_Given

While 1
$x = MessageBox("Error 4408 : Please call helpdesk", "4408 ERROR!")
$x = SetFocus("4408")
Loop

EndIf

IF $Current_Month > $Month_Loan_Given + 2

While 1
$x = MessageBox("Error 4408 : Please call helpdesk", "4408 ERROR!")
$x = SetFocus("4408")
Loop

EndIf

sleep 10

exit


Probably not very elegant but it seems to work.


Glenn BarnasAdministrator
(KiX Supporter)
2009-05-14 03:13 PM
Re: Date checking

TimeDiff() can do this easily:
 Code:
If TimeDiff($DateVar,  'now', 'd') > 30
  "File is more than 30 days old!" ?
EndIf
You can use "today" for midnight of the current day instead of "now", which is the current date/time. Depends on your needs. This doesn't take into account the number of days in the month, but between TimeDiff and TimeConvert, it's fairly easy to do.

TimeConvert converts dates to cTime values (number of seconds since a date) while TimeDiff returns the number of (milli)seconds between to timestamps. It can also accept a Format parameter to return the difference in minutes, hours, days, or years (including fractional parts).

Glenn


kelp7
(Starting to like KiXtart)
2009-05-14 03:29 PM
Re: Date checking

There aren't any files involved.... also, take the quotes out of my top two variables in my script as i've just realised i made them into strings rather than numerics...