Page 1 of 1 1
Topic Options
#193848 - 2009-05-14 02:45 PM Date checking
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
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

Top
#193853 - 2009-05-14 03:13 PM Re: Date checking [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
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.

Top
#193854 - 2009-05-14 03:13 PM Re: Date checking [Re: kelp7]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193857 - 2009-05-14 03:29 PM Re: Date checking [Re: Glenn Barnas]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
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...
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.05 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org