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

Input a dynamic date variable

  • Dark
    Light
  • PDF

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 Variable Explanation
%_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 Variable Conversion Example
%_today+1% Tomorrow 2014-04-30
%_today+2% 2 days from today 2014-05-01
%_today+3% 2 days from today 2014-05-02
%_today+30% 30 days from today 2014-05-29
%_today-1% Yesterday 2014-04-28
%_today-7% This day last week 2014-04-22

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

System Variable Conversion Example
%_now+1h% An hour from now 2014-04-29 13:23:00
%_now+2d6h% 2 days, 6 hours 2014-05-01 18:23:00
%_now-1d12h% 1 day and 12 hours ago 2014-04-28 00:23:00
%_now-7% Exactly 1 week ago at this time 2014-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 Variable Conversion
%_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 Code Function
d The day of the month, from 1 through 31. For example, 6/1/2009 1:45:30 PM becomes 1.
dd The day of the month, from 01 through 31. For example, 6/1/2009 1:45:30 PM becomes 01.
ddd The abbreviated name of the day of the week. For example, 6/15/2009 1:45:30 PM becomes Mon (en-US).
dddd The full name of the day of the week. For example, 6/15/2009 1:45:30 PM becomes Monday.
g The period or era. For example, 6/15/2009 1:45:30 PM becomes A.D..
h The hour, using a 12-hour clock from 0 to 11. For example, 6/15/2009 1:45:30 AM becomes 1
h The hour, using a 12-hour clock from 0 to 11. For example, 6/15/2009 1:45:30 AM becomes 1.
hh The hour, using a 12-hour clock from 00 to 11. For example, 6/15/2009 1:45:30 AM becomes 01.
H The hour, using a 24-hour clock from 0 to 23. For example, 6/15/2009 1:45:30 AM becomes 1.
HH The hour, using a 24-hour clock from 00 to 23. For example, 6/15/2009 1:45:30 AM becomes 01.
m The minute, from 0 through 59. For example, 6/15/2009 1:09:30 AM becomes 9.
mm The minute, from 00 through 59. For example, 6/15/2009 1:09:30 AM becomes 09.
M The month, from 1 through 12. For example, 6/15/2009 1:45:30 PM becomes 6.
MM The month, from 01 through 12. For example, 6/15/2009 1:45:30 PM becomes 06.
MMM The abbreviated name of the month. For example, 6/15/2009 1:45:30 PM becomes Jun.
MMMM The full name of the month. For example, 6/15/2009 1:45:30 PM becomes June.
s The second, from 0 through 59. For example, 6/15/2009 1:45:09 PM becomes 9.
ss The second, from 00 through 59. For example, 6/15/2009 1:45:09 PM becomes 09.
t The first character of the AM/PM designator. For example, 6/15/2009 1:45:30 PM becomes P.
tt The AM/PM designator. For example, 6/15/2009 1:45:30 PM becomes PM.
y The year, from 0 to 99. For example, 1/1/0001 12:00:00 AM becomes 1.
yy The year, from 00 to 99. For example, 1/1/0001 12:00:00 AM becomes 01.
yyy The year, with a minimum of three digits. For example, 1/1/0001 12:00:00 AM becomes 001.
yyyy The year as a four-digit number. For example, 1/1/0001 12:00:00 AM becomes 0001.
yyyyy The 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 character The 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?