Manipulating Date/Time in a Project

View some of the Frequently Asked Questions to our support staff. Included are some tips and tricks making this forum ideal for users getting started with GoAnywhere MFT. Note: Users can reply to existing topics but only our support staff can add new topics to this forum.
1 post Page 1 of 1

Support_Nolan

User avatar
Posts: 8
Joined: Mon May 21, 2018 10:54 am

Post by Support_Nolan » Wed May 01, 2019 3:07 pm
Question:

How do I manipulate date/time in my project?

Answer:

Retrieving the current time

GoAnywhere provides two date and time methods for performing various operations on strings and data. They are Functions and the Timestamp task. Both methods allow you to:

  • Append the current date to file name following a file transfer
  • Use a date and time function to make decisions in a Project
  • Add the current date and time to a file or database
Date and Time Functions will use the current date/time when the function is processed during the project execution. Function values are only stored in memory if they are assigned to a variable.

Timestamp Examples
${CurrentTime()} - Returns the value "HH:mm:ss" (for example, 13:30:24).
${CurrentTime('hh:mm a')} - Returns the example value 1:30 PM.
${CurrentDate()} - Returns the value "yyyy-MM-dd" (for example, 2011-12-31).
${CurrentDate('MM/dd/yy')} - Returns the example value 12/31/11.

How to adjust date/time

If you are looking to adjust the date or time by a value, you can use the AdjustDateTime() function.
Example: If you are looking to adjust the date by minus 90 days, you would use
${AdjustDateTime(CurrentDate('MM/dd/yyyy'), 'MM/dd/yyyy', 'days', -90)}
AdjustDateTime.PNG
AdjustDateTime.PNG (36.81 KiB) Viewed 15161 times

If you are looking to find the difference between timestamps, you can use the DateDiff() function.
DateDiff(dateTime1, pattern1, dateTime2, pattern2, durationCode)
Returns the difference in time based on the duration code between the dates specified in the first and third parameters.
Example: ${DateDiff('24-11-2016', 'dd-MM-yyyy', '2016-11-29', 'yyyy-MM-dd', 'days')} returns 5

If you are looking to convert time to milliseconds, you can use the CurrentTimeMillis() to get the time stamp in milliseconds.
To convert back from milliseconds to readable time, you can use the FormatTimestamp() task.

Here is the list of date/time functions you can use to manipulate time in your project. Keep in mind if one or more of these functions are not in your functions list you will need to upgrade your GoAnywhere MFT.

Functions:

  • AdjustDateTime(dateTime, pattern, durationCode, duration)
    Adds or subtracts duration from the dateTime parameter.
    Example: ${AdjustDateTime('08:15:55 AM', 'hh:mm:ss a', 'minutes', -5)} returns 08:10:55 AM
  • CurrentDate([pattern])
    Returns the current date. If a pattern is not specified the format will use the ISO standard.
    Example: ${CurrentDate()} returns 2011-12-31
  • CurrentTime([pattern])
    Returns the current time. If a pattern is not specified the format will use the ISO standard.
    Example: ${CurrentTime()} returns 13:30:00
  • CurrentTimeMillis()
    Returns the current time in milliseconds.
    Example: ${currenttimemillis()} returns 1325342402619
  • CurrentTimestamp([pattern])
    Returns the current timestamp. If a pattern is not specified the format will use the ISO standard.
    Example: ${CurrentTimestamp()} returns 2011-12-31 13:30:00.786
  • DateDiff(dateTime1, pattern1, dateTime2, pattern2, durationCode)
    Returns the difference in time based on the duration code between the dates specified in the first and third parameters.
    Example: ${DateDiff('24-11-2016', 'dd-MM-yyyy', '2016-11-29', 'yyyy-MM-dd', 'days')} returns 5
  • DateMillis(dateTime, pattern)
    Returns date and time in milliseconds.
    Example: ${DateMillis('24-11-2016 18:42:21.685', 'dd-MM-yyyy HH:mm:ss.SSS')} returns 1480034541685
  • ExtractDateTime(dateTime, pattern, extractType)
    Returns the single part of a date/time field specified in the third parameter.
    Example: ${ExtractDateTime('08:15:55 AM', 'hh:mm:ss a', 'minutes') returns 15
  • FormatTimestamp(timeInMillis, pattern)
    Returns a timestamp based on the milliseconds passed in with the formatting applied from the second parameter.
    Example: ${FormatTimestamp(1325342402619,'yyyy-MM-dd')} returns 2011-12-31
  • ReformatDateTime(dateTime, pattern, newPattern)
    Converts a date or time in the format specified in the second parameter to the format specified in the third parameter.
    ${ReformatDateTime('22-01-2015 10:15:55 AM', 'dd-M-yyyy hh:mm:ss a', 'yyyy-MM-dd HH:mm:ss') returns 2015-01-22 10:15:55
More information about Dates, Times, and Timestamps can be found in the user guide or in the web help guide.
where-can-i-find-documentation-about-go ... teway-1392
Nolan Priebe
Support Analyst
e. [email protected]
p. 1-800-949-4696
w. GoAnywhere.com | HelpSystems.com
1 post Page 1 of 1