Page 1 of 1

Subtract one day from date

Posted: Mon Jun 08, 2015 1:26 pm
by dglaser
I am looking for a way to subtract one day from a date that is not the current date. The TimeStamp task works great for subtracting days from the current date but it does not appear to be able to subtract days from any other date. My ultimate goal is to get the last modified date of a file and subtract one day from it.


Re: Subtract one day from date

Posted: Mon Jun 08, 2015 4:11 pm
by Support_Rick

Here's an easy way to make this a "utility" project and call it when you need to from other projects:
Code: Select all
<project name="Subtract NoDays From FromDate" mainModule="Main" version="2.0" logLevel="silent">
	<variable name="FromDate" value="2015-06-01" />
	<variable name="NoDays" value="2" />
	<variable name="DateLessNoDays" value="" />

	<module name="Main">

		<sql label="Connect to MSSQL" resourceId="MSSQL Local" version="1.0">
			<query label="Select Date Value" outputVariable="NewDate">
				<statement>SELECT DATEADD(day, -${NoDays}, &apos;${FromDate} 00:00:00.000&apos;)</statement>

		<setVariable label="SetVar:  DateLessNoDays" name="DateLessNoDays" value="${NewDate[1]}" version="1.0" />

		<print label="(Status) Show Date" version="1.0">
DateLessNoDays:  ${DateLessNoDays}


You can use MSSQL or MySQL or DB2, etc ... pretty much any DB that you can connect to.

Otherwise, calculate the Milliseconds of the FROMDATE and Subtract 86400000*NoDays from it. Then, re-format your timestamp to display as needed.