Date functions
There are several date functions implemented in Calculate Fields, so the user can manipulate dates in many ways. Most of the functions uses a format parameter, which is used to set the result of the functions formatted as the user wants to. The options for these formats are equivalent with the PHP format parameters:
Format character | Description | Example returned values |
---|---|---|
For day |
||
d |
Day of the month, 2 digits with leading zeros |
01 to 31 |
D |
A textual representation of a day, three letters |
Mon through Sun |
j |
Day of the month without leading zeros |
1 to 31 |
l |
A full textual representation of the day of the week |
Sunday through Saturday |
N |
ISO-8601 numeric representation of the day of the week |
1 (for Monday) through 7 (for Sunday) |
S |
English ordinal suffix for the day of the month, 2 characters |
st, nd, rd or th. Works well with j |
w |
Numeric representation of the day of the week |
0 (for Sunday) through 6 (for Saturday) |
z |
The day of the year (starting from 0) |
0 through 365 |
For week |
||
W |
ISO-8601 week number of year, weeks starting on Monday |
42 (the 42nd week in the year) |
For month |
||
F |
A full textual representation of a month, such as January or March |
January through December |
m |
Numeric representation of a month, with leading zeros |
01 through 12 |
M |
A short textual representation of a month, three letters |
Jan through Dec |
n |
Numeric representation of a month, without leading zeros |
1 through 12 |
t |
Number of days in the given month |
28 through 31 |
For year |
||
L |
Whether it’s a leap year |
1 if it is a leap year, 0 otherwise |
o |
ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead |
1999 or 2003 |
Y |
A full numeric representation of a year, 4 digits |
1999 or 2003 |
y |
A two digit representation of a year |
99 or 03 |
For time |
||
a |
Lowercase Ante meridiem and Post meridiem |
am or pm |
A |
Uppercase Ante meridiem and Post meridiem |
AM or PM |
B |
Swatch Internet time |
000 through 999 |
g |
12-hour format of an hour without leading zeros |
1 through 12 |
G |
24-hour format of an hour without leading zeros |
0 through 23 |
h |
12-hour format of an hour with leading zeros |
01 through 12 |
H |
24-hour format of an hour with leading zeros |
00 through 23 |
i |
Minutes with leading zeros |
00 to 59 |
s |
Seconds, with leading zeros |
00 through 59 |
For timezone |
||
e |
Timezone identifier |
UTC, GMT, Atlantic/Azores |
l |
Whether or not the date is in daylight saving time |
1 if Daylight Saving Time, 0 otherwise |
O |
Difference to Greenwich time (GMT) in hours |
+0200 |
P |
Difference to Greenwich time (GMT) with colon between hours and minutes |
+02:00 |
T |
Timezone abbreviation |
EST, MDT |
Z |
Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. |
-43200 through 50400 |
For full date/time |
||
c |
ISO 8601 date |
2004-02-12T15:19:21+00:00 |
r |
RFC 2822 formatted date |
Thu, 21 Dec 2000 16:01:07 +0200 |
U |
Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) |
For all functions without timestamp parameter, we assume that the current date/time is 2016.04.29. 15:08:03
date
Signature |
{date(format; timestamp)} |
Parameters |
format: format text |
timestamp: date/time value |
|
Description |
Creates a date in the given format |
Returns |
timestamp in the given format |
Example call |
{date(ymd; 2016-02-11)} returns 160211 |
now
Signature |
{now(format)} |
Parameters |
format: format text |
Description |
Creates the actual date/time in the given format |
Returns |
Current date/time in the given format |
Example call |
{now(Y-m-d H:i:s)} returns 2016-04-29 15:08:03 |
yesterday
Signature |
{yesterday(format)} |
Parameters |
format: format text |
Description |
Creates yesterday’s date/time in the given format |
Returns |
Yesterday’s date/time in the given format |
Example call |
{yesterday(Y-m-d H:i:s)} returns 2016-04-28 15:08:03 |
tomorrow
Signature |
{tomorrow(format)} |
Parameters |
format: format text |
Description |
Creates tomorrow’s date/time in the given format |
Returns |
Tomorrow’s date/time in the given format |
Example call |
{tomorrow(Y-m-d H:i:s)} returns 2016-04-30 15:08:03 |
datediff
Signature |
{datediff(timestamp1; timestamp2; unit)} |
Parameters |
timestamp1: date/time value |
timestamp2: date/time value |
|
unit: years/months/days/hours/minutes/seconds; default: days |
|
Description |
Subtracts timestamp2 from timestamp1 |
Returns |
The difference between the two dates returned in unit |
Example call |
{datediff(2016-02-01; 2016-04-22; days)} returns 81 |
addYears
Signature |
{addYears(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Adds amount years to timestamp |
Returns |
Incremented date in format |
Example call |
{addYears(Ymd; 2016-04-22; 1)} returns 20170422 |
addMonths
Signature |
{addMonths(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Adds amount months to timestamp |
Returns |
Incremented date in format |
Example call |
{addMonths(Ymd; 2016-04-22; 1)} returns 20160522 |
addDays
Signature |
{addDays(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Adds amount days to timestamp |
Returns |
Incremented date in format |
Example call |
{addDays(Ymd; 2016-04-22; 1)} returns 20160423 |
addHours
Signature |
{addHours(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Adds amount hours to timestamp |
Returns |
Incremented date in format |
Example call |
{addHours(Ymd H:i:s; 2016-04-22 23:30; 5)} returns 20160423 04:30:00 |
addMinutes
Signature |
{addMinutes(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
amount: decimal number |
Description |
Adds amount minutes to timestamp |
Returns |
Incremented date in format |
Example call |
{addMinutes(Ymd H:i:s; 2016-04-22 22:58; 5)} returns 20160422 23:03:00 |
addSeconds
Signature |
{addSeconds(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Adds amount seconds to timestamp |
Returns |
Incremented date in format |
Example call |
{addSeconds(Ymd H:i:s; 2016-04-22 22:58; 5)} returns 20160422 22:58:05 |
subtractYears
Signature |
{subtractYears(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Subtracts amount years from timestamp |
Returns |
Decremented date in format |
Example call |
{subtractYears(Ymd; 2016-04-22; 5)} returns 20110422 |
subtractMonths
Signature |
{subtractMonths(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Subtracts amount months from timestamp |
Returns |
Decremented date in format |
Example call |
{subtractMonths(Ymd; 2016-04-22; 5)} returns 20151122 |
subtractDays
Signature |
{subtractDays(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Subtracts amount days from timestamp |
Returns |
Decremented date in format |
Example call |
{subtractDays(Ymd; 2016-04-22; 5)} returns 20160417 |
subtractHours
Signature |
{subtractHours(format; timestamp; amount)} |
Parameters |
format: format text |
timestamp: date/time value |
|
amount: decimal number |
|
Description |
Subtracts mount hours from timestamp |
Returns |
Decremented date in format |
Example call |
{subtractHours(Ymd H:i:s; 2016-04-22 12:37; 5)} returns 20160422 07:37:00 |