Input a dynamic date variable
  • 24 May 2021
  • 5 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Input a dynamic date variable

  • Dark
    Light
  • PDF

Article Summary

You can use a dynamic date variable to insert dates into web pages relative to the current time. This method supports custom formatting, offsets, and other advanced features.

Introduction
The dynamic date variable uses the following convention:

  • %_today±offset:date-format%, which gives today's date in Mozenda's home time zone (Mountain Time, UTC -7)
  • %_todayutc±offset:date-format%, which gives today's date in Coordinated Universal Time (UTC).

You can replace ±offset with the number of days ahead of (+) or behind (-) today’s date—e.g., +5.

The date’s format can customized. Replace date-format with the date format you’d like to use. For example, you want the agent to always enter a date that is 7 days ahead of the current date in yyyy-MM-dd format. In this case, the dynamic date variable would look like this:
%_today+7:yyyy-MM-dd%

If today’s date were January 1, 2000, the dynamic date variable above would produce the following output:
2000-01-08

Walkthrough

  1. Select the text box where you want to use the dynamic date variable. Notice that the date field in the sample website specifies how the date should be formatted.
  2. Instead of an actual date, enter the dynamic date variable. If the website specifies how the date should be formatted, the dynamic date variable should match that format exactly.
  3. CREATE ACTION.

In-depth explanation
Date System Variables

The following Mozenda system variables can be used in a Set User Input action to enter date values in text and drop-down boxes in a web form:

Date VariableExplanation
%_today%Sets a date value for the current day (year, month and day) at 12 AM according to Mountain Time Zone.
%_todayutc%Sets a date value for the current day (year, month, day) at 12 AM according to Universal Coordinated Time (UTC).
%_now%Sets a date value of the current moment (year, month, day, hour, minute, second) in time according to Mountain Time Zone.
%_nowutc%Sets a date/time value of the current moment (year, month, day, hour, minute, second) in time according to Coordinated Universal Time (UTC).

Manipulate the date

%_today% and %_now% system variables can be manipulated to return a past or future date/time. Here are some examples of date conversions:

Add/subtract days
This table assumes today’s date is April 29th, 2014.

System VariableConversionExample
%_today+1%Tomorrow2014-04-30
%_today+2%2 days from today2014-05-01
%_today+3%2 days from today2014-05-02
%_today+30%30 days from today2014-05-29
%_today-1%Yesterday2014-04-28
%_today-7%This day last week2014-04-22

Add/subtract days, hours, minutes, seconds
This table assumes today’s date is April 29th, 2014 12:23:00.

System VariableConversionExample
%_now+1h%An hour from now2014-04-29 13:23:00
%_now+2d6h%2 days, 6 hours2014-05-01 18:23:00
%_now-1d12h%1 day and 12 hours ago2014-04-28 00:23:00
%_now-7%Exactly 1 week ago at this time2014-04-22 12:23:00

Although a dynamic date variable can include days, hours, minutes, and seconds, a variable can only be changed by days and hours.

Format the date
You can customize the format used by the dynamic date variable. Here are some examples of date formats that can be used:

System VariableConversion
%_today:MMMM dd, yyyy%April 29, 2014
%_today:MMM ‘yy%Apr ’29
%_today+1:d%29 (a single digit date—such as the 5th—would appear without a leading zero: 5)
%_now:yyyy-MM-dd HH:mm%2014-04-29 12:23
%_now+6h:h tt%9 PM

Input format variables
Different characters can be used in a dynamic date variable to achieve different date formats:

Date CodeFunction
dThe day of the month, from 1 through 31. For example, 6/1/2009 1:45:30 PM becomes 1.
ddThe day of the month, from 01 through 31. For example, 6/1/2009 1:45:30 PM becomes 01.
dddThe abbreviated name of the day of the week. For example, 6/15/2009 1:45:30 PM becomes Mon (en-US).
ddddThe full name of the day of the week. For example, 6/15/2009 1:45:30 PM becomes Monday.
gThe period or era. For example, 6/15/2009 1:45:30 PM becomes A.D..
hThe hour, using a 12-hour clock from 0 to 11. For example, 6/15/2009 1:45:30 AM becomes 1
hThe hour, using a 12-hour clock from 0 to 11. For example, 6/15/2009 1:45:30 AM becomes 1.
hhThe hour, using a 12-hour clock from 00 to 11. For example, 6/15/2009 1:45:30 AM becomes 01.
HThe hour, using a 24-hour clock from 0 to 23. For example, 6/15/2009 1:45:30 AM becomes 1.
HHThe hour, using a 24-hour clock from 00 to 23. For example, 6/15/2009 1:45:30 AM becomes 01.
mThe minute, from 0 through 59. For example, 6/15/2009 1:09:30 AM becomes 9.
mmThe minute, from 00 through 59. For example, 6/15/2009 1:09:30 AM becomes 09.
MThe month, from 1 through 12. For example, 6/15/2009 1:45:30 PM becomes 6.
MMThe month, from 01 through 12. For example, 6/15/2009 1:45:30 PM becomes 06.
MMMThe abbreviated name of the month. For example, 6/15/2009 1:45:30 PM becomes Jun.
MMMMThe full name of the month. For example, 6/15/2009 1:45:30 PM becomes June.
sThe second, from 0 through 59. For example, 6/15/2009 1:45:09 PM becomes 9.
ssThe second, from 00 through 59. For example, 6/15/2009 1:45:09 PM becomes 09.
tThe first character of the AM/PM designator. For example, 6/15/2009 1:45:30 PM becomes P.
ttThe AM/PM designator. For example, 6/15/2009 1:45:30 PM becomes PM.
yThe year, from 0 to 99. For example, 1/1/0001 12:00:00 AM becomes 1.
yyThe year, from 00 to 99. For example, 1/1/0001 12:00:00 AM becomes 01.
yyyThe year, with a minimum of three digits. For example, 1/1/0001 12:00:00 AM becomes 001.
yyyyThe year as a four-digit number. For example, 1/1/0001 12:00:00 AM becomes 0001.
yyyyyThe year as a five-digit number. For example, 1/1/0001 12:00:00 AM becomes 00001.
\The escape character. For example, 6/15/2009 1:45:30 PM (h h) becomes 1 h.
Any other characterThe character is copied to the result string unchanged.
Notes

Capital M designates the month format. Lower-case m is reserved for the minute value.
Suppose the current moment in time is January 1, 2000 10:15 AM. Using yyyy-mm-dd would return 2000-15-01 (note that the minute value is where the month normally appears). Using yyyy-MM-dd would yield2000-01-01`.


Was this article helpful?