Skip to content

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.
  • dglaser Offline
  • Posts: 2
  • Joined: Mon Jun 08, 2015 1:18 pm

Subtract one day from date

Post 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.

Thanks,
Drew
  • Support_Rick Offline
  • Support Specialist
  • Posts: 590
  • Joined: Tue Jul 17, 2012 2:12 pm
  • Location: Phoenix, AZ
  • Contact:

Re: Subtract one day from date

Post by Support_Rick »

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
Post Reply