check_dateargument

including 1 day mode

This Subroutines checks if the FROM and TO date are in order. In the case that there is only 1 day entered, it will automatically fill in the second day in a "1 Day Mode".

Syntax

gosub check_dateargument ()

Code Snippet

subroutine check_dateargument {
	# Validate that amount of input arguments is as expected
	if (${ARGC} != 2) {
		if (${ARGC} == 1) {
			print "Running in 1 day mode"
			var firstday = ${ARG_1}
			var lastday = (@DATEADD(${firstday}, 1))
		} else {
			print "This requires 1 or 2 arguments, the day to collect usage for, and the date following that day, both in YYYYMMDD format"
			terminate with error
		}
	} else {
		var firstday = ${ARG_1}
		var lastday = ${ARG_2}
	}
	
	# Validate that to date is not before from date
	if (${firstday} > ${lastday}) {
		print "TO date cannot be a date that lies before FROM date"
		terminate with error
	}
	# Validate that to date is not the same as from date
	if (${firstday} == ${lastday}) {
		print "TO date cannot be the same as FROM date"
		terminate with error
	}
}

Last updated