Cognito Forms logo

Date/Time calculations

Here is a full list of supported text functions that you can call by typing a period after a Date, Time, or Date & Time field. 

Returns

Function

Description

DateTime

AddDays(Number)

Returns a new DateTime that adds the specified number of days to the value of this instance.

DateTime

AddHours(Number)

Returns a new DateTime that adds the specified number of hours to the value of this instance.

DateTime

AddMilliseconds(Number)

Returns a new DateTime that adds the specified number of milliseconds to the value of this instance.

DateTime

AddMinutes(Number)

Returns a new DateTime that adds the specified number of minutes to the value of this instance.

DateTime

AddMonths(Number)

Returns a new DateTime that adds the specified number of months to the value of this instance.

DateTime

AddSeconds(Number)

Returns a new DateTime that adds the specified number of seconds to the value of this instance.

DateTime

AddYears(Number)

Returns a new DateTime that adds the specified number of years to the value of this instance.

Number

CompareTo(DateTime)

Compares the value of this instance to a specified DateTime value.  Returns -1, 0, or 1 which means the instance is earlier, equal to, or later than the value, respectively.

DateTime

Date

Returns a new DateTime that represents the date component of this instance.

Number

Day

Returns the day of the month represented by this instance.

String

DayOfWeek

Returns the day of the week represented by this instance.  (i.e. Tuesday or Sunday)

Number

DayOfYear

Returns the day of the year represented by this instance.

Number

Hour

Returns the hour component of the instance.

Number

Millisecond

Returns the millisecond component of the instance.

Number

Minute

Returns the minute component of the instance.

Number

Month

Returns the month component of the instance.

Number

Second

Returns the second component of the instance.

Number

Ticks

Returns the number of ticks (100 nanoseconds) since 1/1/1970 represented by this instance.

Number

Year

Returns the year component of the instance.

 

In addition to these functions, you can access the following by typing DateTime. , followed by the appropriate function. Cognito Forms also supports relative syntax when entering literal date values, such as "Today" and "Tomorrow". Unlike DateTime., you do not need to use an equal sign (=) before inputting a relative value:

                                     

Returns

Name

Description

Yes/No

DateTime.IsLeapYear(Number)

Returns a value indicating whether the specified year is a leap year.

DateTime

"Now" or DateTime.Now

Returns a DateTime object set to the current date and time, expressed as the local time.

DateTime "Yesterday" Returns a DateTime object set to the day before the current date.
DateTime "Tomorrow" Returns a DateTime object set to the day after the current date.
DateTime "Next Week" Returns a DateTime object set to 7 days after the current date.
DateTime "Last Week" Returns a DateTime object set to 7 days before the current date.
DateTime "Next Month" Returns a DateTime object set to a month after the current date.
DateTime "Last Month" Returns a DateTime object set to a month before the current date.
DateTime "2 hours" or "2 hours from now" Returns a DateTime object set to specified number of hours after the current date.
DateTime

"-3 days" or "3 days ago"

Returns a DateTime object set to specified number of days before the current date.
DateTime "Next Year" Returns a new DateTime that adds one year to the current date.
DateTime "Last Year" Returns a new DateTime that subtracts one year from current date.
DateTime "1 year 4 months" Returns a DateTime object set to specified number of years and months after the current date.

DateTime

DateTime.Parse(String)

Converts the string representation of a date and time to its DateTime equivalent.  You can also just specify

DateTime

"Today" or DateTime.Today

Returns a DateTime object set to the current date.

 

Date/time formats

After inserting a Date field on your form, you can customize the format of the date or time as it appears on other parts of your form. To do this, simply enter a formatted string into a calculation field, like so:

 

 

Here is a full list of possible date/time formats:

Function Returns Description
Date.ToString("d / M / yyyy") 6 / 10 / 2015 Day from 1 through 31, month, from 1 through 12, full year
Date.ToString("d / MM / yyyy") 6 / 10 / 2015 Day from 1 through 31, month, from 01 through 12, full year
=Date.ToString("d / MMM / yyyy") 6 / Oct / 2015 Day from 1 through 31, abbreviated month, full year
Date.ToString("d / MMMM / yyyy") 6 / October / 2015 Day from 1 through 31, full month, full year
Date.ToString("dd / MMMM / yyyy") 06 / October / 2015 Day from 01 through 31, full month, full year
Date.ToString("ddd / MMMM / yyyy") Tue / October / 2015 The abbreviated name of the day of the week, full month, full year
Date.ToString("dddd / MMMM / yyyy") Tuesday / October / 2015 The full name of the day of the week, full month, full year
Date.ToString("d / MMMM / yy") 6 / October / 15 Day from 1 through 31, full month, The year, from 00 to 99
Time.ToString("h : m tt") 3 : 46 PM Hour, using a 12-hour clock from 1 to 12, minute, from 0 through 59, AM/PM designator
Time.ToString("hh : mm tt") 03 : 46 PM Hour, using a 12-hour clock from 01 to 12, minute, from 00 through 59, AM/PM designator
Time.ToString("H : mm tt") 15 : 46 PM Hour, using a 24-hour clock from 0 to 23, minute, from 00 through 59, AM/PM designator
Time.ToString("HH : mm tt") 15 : 46 PM Hour, using a 24-hour clock from 00 to 23, minute, from 00 through 59, AM/PM designator

 

Entry dates

Here are three different date/time values that you can call by typing a period after Entry:

Entry Created Returns a DateTime set when an entry is saved for the first time via Save & Resume.
Entry Submitted Returns a DateTime set each time an entry is submitted.
Entry Updated Returns a DateTime set each time an entry is updated.

 

Time Span functions

TimeSpan represents a time interval, and is the result of subtracting two Date or Time values.

Returns

Name

Description

Number

Days

Returns the days component of the time interval represented by this instance.

Number

Hours

Returns the hours component of the time interval represented by this instance.

Number

Milliseconds

Returns the milliseconds component of the time interval represented by this instance.

Number

Minutes

Returns the minutes component of the time interval represented by this instance.

Number

Seconds

Returns the seconds component of the time interval represented by this instance.

Number

Ticks

Returns the ticks (100 nanoseconds) component of the time interval represented by this instance.

String

ToString(String)

Converts the value of the TimeSpan instance to its equivalent string using the specified format.  Options: “c”(00:00:00), “g”(0:00:00), “G”(0:00:00:00.0000), “hh\:mm\:ss”(00:00:00).

Number

TotalDays

Returns the value of this instance expressed in whole and fractional days.

Number

TotalHours

Returns the value of this instance expressed in whole and fractional hours.

Number

TotalMilliseconds

Returns the value of this instance expressed in whole and fractional milliseconds.

Number

TotalMinutes

Returns the value of this instance expressed in whole and fractional minutes.

Number

TotalSeconds

Returns the value of this instance expressed in whole and fractional seconds.

 

 

Printable View