Format Date Time Action Icon

Format Date Time

Declaration

<AMTEXTFORMATDATETIME DATETIMEFORMAT="text" INCLUDEAMPM="YES/NO" RESULTVARIABLE="text" ACTION="text(options)" SPECIFIEDDATETIME="date" SPECIFIEDFORMAT="date format" ADJUSTYEAR="number" ADJUSTDAY="number" />

See Also

Convert Case | Find Text | Format Date/Time | Get Subtext | Insert Text | Pad Text | Replace Text | Trim Text

Description

Converts a date and/or time into the specified format.

Practical Usage

Used to modify a date value so that it matches a required format. For example, the application being automated may require a date to be input in a specific format such as yyyy-dd-mm. This action would be used to modify the value accordingly.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

Date time format

Text

Yes

(Empty)

DATETIMEFORMAT="dd/mm/yyyy hh:nn:ss"

The format that should be used when the date is output. Click the provided drop-down arrow to select a specific format from the list that appears or you can manually enter a custom format using valid characters. The following special characters are used to create a date format:

y = year

m = month  

d = day

h = hour

n = minutes = second

hh = leading zero (Example: 03)

h = no leading zero (Example: 3)

NOTE: The result will appear in its entirety in the Formatted date time field.

12 hour format

Yes/No

No

Yes

SPECIFIED12HOUR="no"

Specifies whether hours of the day will be based on a 12 or 24 hour clock. If set to YES (default), a 12 hour clock format will be used. If set to NO, a 24 hour clock format will be used.

Include AM/PM in result

Yes/No

No

No

INCLUDEAMPM="yes"

Indicates whether an AM or PM indicator should be added to the end of the formatted date time value. If set to YES, the formatted date will be followed with an AM or PM indicator. If set to NO (default), no AM/PM indicator will be included. This option is only available if the 12 hour format parameter is set to YES.

Populate Variable with Result

Text

Yes

(Empty)

RESULTVARIABLE="varname"

Indicates an already existing variable in which to populate with the formatted date/time.

 

Advanced Properties

Property

Type

Required

Default

Markup

Description

Action

Text (options)

No

Use current date time

ACTION="specified"

Specifies the source of the date time value to be formatted. Different parameters become available depending on the option selected. The available options are:

  • Use current date time (default): The current date and time will be used.

  • Use specified date time: The specified date and time will be used.

  • Prompt user: At runtime, a dialog is presented prompting the user to select a date/time.

Specified Date Time

Text

Yes if Action is set to Use specified date time

Current date/time

PECIFIEDDATETIME="6/12/2005 1:42:40 PM"

Indicates the date/time to format. This parameter is available only if the Action parameter is set to Use specified date time.

Will be in the format

Text

Yes if Action is set to Use specified date time

m/d/yyyy h:nn:ss

SPECIFIEDFORMAT="dd/mm/yy hh:nn:ss"

The format that should be applied when attempting to read the date/time entered in the Specified Date Time parameter. This parameter is available only if the Action parameter is set to Use specified date time.

Prompt Message

Text

Yes if Action is set to Prompt user

(Empty)

PROMPTMESSAGE="Please select the date/time"

The message that should appear along with the date/time prompt dialog box during runtime. This is useful in providing the user proper instructions (Example: Please select the date/time). This parameter is available only if the Action parameter is set to Prompt user.

Prompt Type

Text (options)

No

Prompt for date and time

PROMPTTYPE="date"

Specifies whether the prompt dialog box should prompt for the date, the time, or both. The available options are:

  • Prompt for date and time: The user will be prompted for both the date and the time. A date/time calendar will appear allowing the user to select a specific date and time.

  • Prompt for time only: The user will be prompted for the time only. A time calendar will appear allowing the user to select a specific time.

  • Prompt for date only: The user will be prompted for the date only. A date calendar will appear allowing the user to select a specific date.

Adjust Year

Number

No

0

ADJUSTYEAR="-4"

Specifies the number of years the date should be adjusted by. A positive or negative number may be used (Example: entering "4" indicates plus 4 years, entering "-4" indicates minus 4 years).

Adjust Hour

Number

No

0

ADJUSTHOUR="4"

Specifies the number of hours the date should be adjusted by. A positive or negative number may be used (Example: entering "4" indicates plus 4 hours, entering "-4" indicates minus 4 hours).

Adjust Month

Number

No

0

ADJUSTMONTH="4"

Specifies the number of months the date should be adjusted by. A positive or negative number may be used (Example: entering "4" indicates plus 4 months, entering "-4" indicates minus 4 months).

Adjust Minute

Number

No

0

ADJUSTMINUTE="-5"

Specifies the number of minutes the date should be adjusted by. A positive or negative number may be used (Example: entering "4" indicates plus 4 minutes, entering "-4" indicates minus 4 minutes).

Adjust Day

Number

No

0

ADJUSTDAY="-4"

Specifies the number of days the date should be adjusted by. A positive or negative number may be used (Example: entering "4" indicates plus 4 days, entering "-4" indicates minus 4 days).

Adjust Second

Number

No

0

ADJUSTSECOND="-30"

Specifies the number of seconds the date should be adjusted by. A positive or negative number may be used (Example: entering "30" indicates plus 30 seconds, entering "-30" indicates minus 30 seconds).

 

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

Sample Task 1 - A 'Format Date Time' action used to prompt the user for a specific date/time. A 'Message Box' action then displays the date and time selected in the following format m-d-yyyy h-nn-ss.

 

<AMVARIABLE NAME="theDateTime"></AMVARIABLE>

<AMTEXTFORMATDATETIME DATETIMEFORMAT="m-d-yyyy h-nn-ss" INCLUDEAMPM="YES" RESULTVARIABLE="theDateTime" ACTION="prompt" PROMPTMESSAGE="Please select date/time." />

<AMMESSAGEBOX>%theDateTime% is the date and time selected.</AMMESSAGEBOX>

 

 

Sample Task 2 - This task uses the 'Format Date Time' action to format the current date to 30 days prior and write the results in Notepad.

 

<AMVARIABLE NAME="CurrentDate"></AMVARIABLE>

<AMVARIABLE NAME="PriorDate"></AMVARIABLE>

<AMTEXTFORMATDATETIME DATETIMEFORMAT="mm-dd-yyyy" RESULTVARIABLE="CurrentDate" />

<AMTEXTFORMATDATETIME DATETIMEFORMAT="mm-dd-yyyy" RESULTVARIABLE="PriorDate" ADJUSTDAY="-30" />

<AMRUN FILE="notepad" />

<AMSENDKEY>The Current Date is %CurrentDate%

The Date 30 days ago was %PriorDate%</AMSENDKEY>

 

 

Sample Task 3 - This task will demonstrate a method to obtain the first and last day of the current month using a few variables and the ‘Format Date Time’ action. The comments (shown in green) within this task will provide further explanation.

 

<AMMESSAGEBOX BUTTONS="ok_cancel" ONSECONDBUTTONCLICK="stop">This task will demonstrate a method to obtain the first and last day of the current month using a few variables and the ‘Format Date Time’ action. The comments (shown in green) within this task will provide further explanation. </AMMESSAGEBOX>

<AMVARIABLE NAME="FirstOfThisMonth"></AMVARIABLE>

<AMVARIABLE NAME="FirstOfNextMonth"></AMVARIABLE>

<AMVARIABLE NAME="LastOfThisMonth"></AMVARIABLE>

<!-- To get the first of this month, hard code the datetime format to mm-01-yyyy. This automatically sets the date to the first day of the current month. -->

<AMTEXTFORMATDATETIME DATETIMEFORMAT="mm-01-yyyy" RESULTVARIABLE="FirstOfThisMonth" />

<!-- To get the first of next month, hard code the datetime format to mm-01-yyyy and adjust by 1 month. This sets the date to the first day of the next month. -->

<AMTEXTFORMATDATETIME DATETIMEFORMAT="mm-01-yyyy" RESULTVARIABLE="FirstOfNextMonth" ADJUSTMONTH="1" />

<!-- To get the last of this month, use the variable that holds the value of the first day of next month (%FirstOfNextMonth%) and adjust by -1 day. -->

<AMTEXTFORMATDATETIME DATETIMEFORMAT="mm-dd-yyyy" RESULTVARIABLE="LastOfThisMonth" ACTION="specified" SPECIFIEDDATETIME="%FirstOfNextMonth%" SPECIFIEDFORMAT="mmddyyyy" ADJUSTDAY="-1" />

<AMMESSAGEBOX>The first day of this month was:&#xD;&#xA;%FirstOfThisMonth%&#xD;&#xA;&#xD;&#xA;The first day of next month is: &#xD;&#xA;%FirstOfNextMonth%&#xD;&#xA;&#xD;&#xA;The last day of this month is: &#xD;&#xA;%LastOfThisMonth%</AMMESSAGEBOX>

 

↑ Top