Page 1 of 1 1
Topic Options
#19392 - 2002-04-03 01:57 PM help with date calculation
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
#19393 - 2002-04-03 02:10 PM Re: help with date calculation
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If you simply want the date 7 days ago, search the forums for the date math calculation routines. These'll save you sooo much aggravation.

Using these routines simply convert the date into an serial format, subtract 7 then convert it back to date format.

They are available from the ScriptLogic site and the UDF forum.

Top
#19394 - 2002-04-03 02:11 PM Re: help with date calculation
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
not sure...
at least you could get the last section shorter:
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

is just the same as:
code:
If $leap="no"
$LAST_YEAR=VAL($year)-1
?"LAST_YEAR="$LAST_YEAR
If 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



[ 03 April 2002, 14:12: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#19395 - 2002-04-03 02:32 PM Re: help with date calculation
Anonymous
Unregistered


Yes, the functions you want are located here:

http://www.scriptlogic.com/Kixtart/FunctionList.asp?FT=Date%20Functions

Top
#19396 - 2002-04-03 04:01 PM Re: help with date calculation
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
#19397 - 2002-04-03 04:11 PM Re: help with date calculation
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I can't understand how it could be the reason.
maybe I try this later, but I quess the thing is somewhere else...

what it says when it crashes?
_________________________
!

download KiXnet

Top
#19398 - 2002-04-03 04:14 PM Re: help with date calculation
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Since you already do the numeric conversion of $LAST_YEAR, eg:

$LAST_YEAR=VAL($year)-1

might thee not be the need to repeatedly do it going forward, eg, maybe change your conditional to this:

If $LAST_YEAR=($LAST_YEAR/400)*400 OR $LAST_YEAR=($LAST_YEAR/4)*4 AND $LAST_YEAR<>($LAST_YEAR/100)*100

-Shawn

Top
#19399 - 2002-04-03 04:56 PM Re: help with date calculation
Richard H. Administrator Offline
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 Offline
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 Offline
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
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 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.032 seconds in which 0.012 seconds were spent on a total of 12 queries. Zlib compression enabled.

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