SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
DateAdd

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
DateAdd
Author Message
pdupuis



Joined: 04 Jan 2007
Posts: 22

Post DateAdd Reply with quote
How can I add 60 months or substract 3 months from a date value?
I saw DateAdd but this is for adding days.

Thanks in advance for your help.
Wed Oct 17, 2007 8:34 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
You can use a VBScript job for that purpose. For example to add 60 months to the current date, use
Code:
FutureDate = DateAdd( "m", 60, "@T"yyyy-mm-dd"" )


Use negative numbers to subtract values

To do the same in JAL, you would need to split date value parts and program some date arithmetic. You can, for example, create a user-defined statement returning the result of the calculations such as MonthAdd( num_month, start_date ) or something similar. This is doable but not very simple, as you would need to take into account leap years in order to make the calculations work correctly for any date.

Another way to do it in JAL is to call the described VBScript function dynamically and capture the result, for example, here is a generic code that can be wrapped to a user-defined statement and called from any job

Code:
// declare script variables
Dim temp_vbs_file, string, "@V"env:TEMP"\\@V"job_id".vbs"
Dim temp_out_file, string, "@V"env:TEMP"\\@V"job_id".out"
Dim pid, number
Dim new_date, date
Dim command, string

// write work file for VBScript
FileSave( temp_vbs_file, "WScript.Echo DateAdd( \"m\", 60, \"@T"yyyy-mm-dd"\")" )

// just in case if the temp path contains spaces, add quotes to file names
ConcatEx( "cmd /C cscript //NoLogo \"", temp_vbs_file, "\" > \"", temp_out_file, "\"", command )

// run this script
RunAndWait( command, "", 0, pid)

// read result
FileReadAll( temp_out_file, new_date )

// delete temp files
FileDelete( temp_vbs_file )
FileDelete( temp_out_file )

Wed Oct 17, 2007 10:44 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.