| 
	
		| 
		
			|  | SoftTree Technologies Technical Support Forums
 |  |  
	
		| 
	
	
	
		| Author | Message |  
		| pdupuis 
 
 
 
 
			
				| Joined: 04 Jan 2007 Posts: 22
 
 |  
 | 
			
				|  DateAdd |   |  
				| 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 |     |  
		|  |  
		| SysOp Site Admin
 
 
 
 
			
				| Joined: 26 Nov 2006 Posts: 7990
 
 |  
 | 
			
				|   |   |  
				| You can use a VBScript job for that purpose. For example to add 60 months to the current date, use 
 
	|  |  
	|  | 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
 
 
 
	|  |  
	|  | // 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 |     |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |  |  |