#19392 - 2002-04-03 01:57 PM
help with date calculation
|
Anonymous
Anonymous
Unregistered
|
Hi all
I have a fully working script that transfers orders onto a FTP server ad then renames the files to an archive extension. ~I am trying to implement a bit of house keeping so we only keep files form the last 7 days, but am getting a bit stuck on what is wrong with my script. first of all I check if it is a leap year withthe following code code:
If $month>02 If Val($y)=(Val($y)/400)*400 OR Val($y)=(Val($y)/4)*4 AND Val($y)<>(Val($y)/100)*100 Val($day)=Val($day)+1 $leap="yes" EndIf EndIf
And this works fine, but if it is not a leap year I need to calculate if last year was as this may also throw out the calculations. I have this code below
code:
If $leap="no" $LAST_YEAR=VAL($year)-1 ?"LAST_YEAR="$LAST_YEAR If Val($LAST_YEAR)=(Val($LAST_YEAR)/400)*400 OR VAL($LAST_YEAR)=(Val($LAST_YEAR)/4)*4 AND VAL($LAST_YEAR)<>(Val($LAST_YEAR)/100)*100 ;Val($day)=Val($day)+1 $prev_leap="yes" EndIf EndIf
However the script keeps crashing at this part of it. I know how to do all the calculations but this part is really bugging me. I'm not sure but I think it may be to do with the val conversions somewhere.
any suggestions??
P.S the day / month /year variants are calculated from the @day macro and are working fine
|
Top
|
|
|
|
#19395 - 2002-04-03 02:32 PM
Re: help with date calculation
|
Anonymous
Anonymous
Unregistered
|
|
Top
|
|
|
|
#19396 - 2002-04-03 04:01 PM
Re: help with date calculation
|
Anonymous
Anonymous
Unregistered
|
Sorry guys, forgot ot mention I am using verison 3.63 of Kix that doesn't support the UDFs, and I can't upgrade it without going through loads of red tape. All I wanted to know really is if I have too many 'val's in there, it seems funny that the first part of code works fine, but the second doesn't even though it is identical except for the variant
|
Top
|
|
|
|
#19399 - 2002-04-03 04:56 PM
Re: help with date calculation
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
The original routines were written for 3.63: Get yer date maths routines here.
|
Top
|
|
|
|
#19400 - 2002-04-03 05:30 PM
Re: help with date calculation
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
This sample is as simple as I can make it, and will work fine with 3.63
1) Set the three date fields $iDay, $iMonth and $iYear. 2) Set $iChange to the number of days to change the date by - negative numbers go back in time. 3) Call the DateMath subroutine.
Now the $iDay, $iMonth and $iYear variables have been adjusted by $iChange.
Here is the code with the example:
code:
$iMonth=3 $iDay=4 $iYear=2002 $iChange=-7
"Date was (DD MM YYYY) $iDay $iMonth $iYear" ? Gosub DateMath "Date is now (DD MM YYYY) $iDay $iMonth $iYear" ? Exit ; ; ; ------------------- ; DateMath Subroutine ; ------------------- :DateMath If $iMonth < 3 $iMonth = $iMonth + 12 $iYear = $iYear - 1 EndIf $iSerial = $iDay + ( 153 * $iMonth - 457 ) / 5 + 365 * $iYear + $iYear / 4 - $iYear / 100 + $iYear / 400 + $iChange $MyH=100*$iSerial-25 $MyA=$MyH/3652425 $MyB=$MyA-$MyA/4 $iYear=(100*$MyB+$MyH)/36525 $MyC=$MyB+$iSerial-365*$iYear-$iYear/4 $iMonth=(5*$MyC+456)/153 $iDay=$MyC-(153*$iMonth-457)/5 If $iMonth > 12 $iYear=$iYear + 1 $iMonth = $iMonth - 12 EndIf Return
[ 03 April 2002, 17:32: Message edited by: Richard Howarth ]
|
Top
|
|
|
|
#19401 - 2002-04-04 12:21 AM
Re: help with date calculation
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
If it were me, I would have the script shell to a program from microsoft called "forfiles.exe". This allows you to do operations on a file based on date and filename with wildcards. That way you all you need is a formatted date rather than a calculation of the last 7 days. Here is the file output with no command-line options:
FORFILES v 1.1 - emmanubo@microsoft.com - 4/98
Syntax : FORFILES [-pPath] [-mSearch Mask] [-ccommand] [-d<+|->] [-s]
-pPath Path where to start searching -mSearch Mask Search files according to -cCommand Command to execute on each file(s) -d<+|-> Select files with date >= or <=DDMMYYYY or files having date >= or <= current date - DD days -s Recurse directories -v Verbose mode
The following variables can be used in Command : @FILE, @FNAME_WITHOUT_EXT, @EXT, @PATH, @RELPATH, @ISDIR, @FSIZE, @FDATE, @FTIME
To include special hexa characters in the command line : use 0xHH .... etc....
It can be found at: ftp://ftp.microsoft.com/reskit/y2kfix/x86/
BrianTX
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 382 anonymous users online.
|
|
|