Topic Options
#1415 - 09/11/07 07:14 PM Date math using script
vonDee Offline
Junior Member

Registered: 09/10/07
Posts: 2
Am trying to calculate the difference between 2 dates/times in minutes or seconds. How do you do this in a script. I can't find a way to do this - could multiply year, day, hour, etc. by number of seconds then taking the difference but then would need to deal with leap years, etc. I'm looking for a way to calculate something like:

The number of seconds between 2007.09.21 21:59:32 and 2007.09.22 03:22:19.

Thanks for any help here.

Top
#1416 - 09/12/07 02:33 PM Re: Date math using script [Re: vonDee]
Luke Tomasello Administrator Online   content
Member

Registered: 09/17/00
Posts: 739
Loc: San Jose, CA., USA
Are wanting to do math on file dates? Like moving / deleting files over a certain number of days old? If so there is an easier way than date math..

 Code:
## move_on_date.tg 
# So, how exactly do I move / delete a file at/over x-days-old? 
# 

{ 
        -name move_on_date
        # fire every second 
        -start -inc 0 0 0 1 

        # if there are no more files, break 
        -action -onerror no_more_files 

        # get the next file, if there are no more files 
        #  we will stop here 
        -action -getfile -newest c:\file_store\*.* THE_FILE 

        # okay, check to see if the files age in days is greater than 15
	#  if so, move to the old_files folder, otherwise, move to the 
	#  temp_folder. 
	# Files in the temp folder will be restored in the no_more_files procedure
        -action -onerror temp_files 
        -action -test "%THE_FILE.AGE.DAYS% > 15" 
        -action -call old_files 

} 

## no_more_files
# Files in the temp_folder will be restored to their original location in this procedure
{ 
        -name no_more_files 
        -action -print there are no more files. restoring from temp dir... 
	-command -hide CMD.EXE /c MOVE /Y "c:\file_store\temp_files\*.*" "c:\file_store" 
        -action -return break 
} 

## temp_files
# move 'NON-OLD' files to a temp folder
{ 
        -name temp_files 
        -action -print temp_files 
        -action -move "%THE_FILE%" "c:\file_store\temp_files\%THE_FILE.FNAME%%THE_FILE.EXT%" 
        -action -return break 
} 

## old_files
# move 'OLD' files to a old_files folder
{ 
        -name old_files 
        -action -print old_files 
        -action -move "%THE_FILE%" "c:\file_store\old_files\%THE_FILE.FNAME%%THE_FILE.EXT%" 
        -action -return break 
}  
_________________________
Regards,
Luke Tomasello

Top
#1417 - 09/12/07 03:08 PM Re: Date math using script [Re: Luke Tomasello]
Luke Tomasello Administrator Online   content
Member

Registered: 09/17/00
Posts: 739
Loc: San Jose, CA., USA
PS. if it's raw dates you want to manipulate, you can write a small bit of VBScript (Wincron runs VBScript, and there lots of examples of how to call VBScript in the \sample scripts folder.)

This is one site that lists all the VB functions you would want .. I think you want DateDiff
http://www.w3schools.com/vbscript/vbscript_ref_functions.asp
_________________________
Regards,
Luke Tomasello

Top


Moderator:  Luke Tomasello