Subtract one day from date

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
2 posts Page 1 of 1

dglaser

Posts: 2
Joined: Mon Jun 08, 2015 1:18 pm

Post by dglaser » Mon Jun 08, 2015 1:26 pm
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.

Thanks,
Drew

Support_Rick

Support Specialist
Posts: 590
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Mon Jun 08, 2015 4:11 pm
DGlaser

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>
			</query>
		</sql>


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


		<print label="(Status) Show Date" version="1.0">
			<![CDATA[
=============================
DateLessNoDays:  ${DateLessNoDays}
=============================]]>
		</print>

	</module>

</project>
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.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
2 posts Page 1 of 1