Date and time functions

A time string can be in any of the following formats:

  1. YYYY-MM-DD

  2. YYYY-MM-DD HH:MM

  3. YYYY-MM-DD HH:MM:SS

  4. YYYY-MM-DD HH:MM:SS.SSS

  5. HH:MM

  6. HH:MM:SS

  7. HH:MM:SS.SSS

  8. now

  9. DDDD.DDDD

Formats 5 through 7 that specify only a time assume a date of 2000-01-01. Format 8 is converted into the current date and time, using Universal Coordinated Time (UTC). Format 9 is the Julian day number expressed as a floating point value.

Most of the Date and Time functions are derived from the uFormatDate function. The only difference is that the other Date and Time functions only return a special format or part of the date and they do not have the first format parameter. Therefore, uDate() is equivalent to uFormatDate("%Y-%m-%d").

Getting the current time

If no date is given, the time string now is assumed and the date is set to the current date and time.

uDate() // returns something like "2006-03-01"
uDate() is equivalent to uDate("now")

Getting a special date

IN.Date = uDate("2004-01-04 14:26:33") // returns the date part "2004-01-04"

Modifiers

The time string can be followed by zero or modifiers that alter the date or alter the interpretation of the date. The available modifiers are as follows:

  1. NNN days

  2. NNN hours

  3. NNN minutes

  4. NNN.NNNN seconds

  5. NNN months (see #551 and [1163])

  6. NNN years (see #551 and [1163])

  7. Start of month

  8. Start of year

  9. Start of week (withdrawn -- will not be implemented)

  10. Start of day

  11. Weekday N (see #551 and [1163])

  12. unixepoch

  13. localtime

  14. utc

  15. Julian

  16. Gregorian

The first size modifiers (1 through 6) simply add the specified amount of time to the date specified by the preceding time string. The “start of” modifiers (7 through 10) shift the date backwards to the beginning of the current month, year, or day. The “weekday” modifier advances the date forward to the next date where the weekday number is N: Sunday is 0, Monday is 1, and so on.

The “unixepoch” modifier (12) works only if it immediately follows a time string in the DDDD.DDDDD format. This modifier causes the DDDD.DDDDD to be interpreted not as a Julian day number as it normally would be, but as the number of seconds since 1970. This modifier allows unix-based times to be converted to Julian day numbers easily. The “localtime” modifier (13) adjusts the previous time string so that it displays the correct local time. “utc” undoes this.

The “Julian” modifier (14) assumes that the time string is a Gregorian date and converts the date into a Julian date: “Gregorian” undoes the work of “Julian.”

Date and time calculations

Compute the current date:

uDate('now')

Compute the last day of the current month.

uDate('now','start of month','+1 month','-1 day')

Compute the date and time given a UNIX timestamp 1092941466:

uDatetime(1092941466, 'unixepoch')

Compute the date and time given a UNIX timestamp 1092941466, and compensate for your local timezone.

uDatetime(1092941466, 'unixepoch', ‘localtime’)

Compute the current UNIX timestamp:

strftime('%s','now')

Compute the number of days since the Battle of Hastings:

uJuliandate('now') - uJuliandate('1066-10-14','gregorian')

Compute the number of seconds between two dates:

julianday('now')*86400 - julianday('2004-01-01 02:34:56')*86400

Compute the date of the first Tuesday in October (January + 9) for the current year:

date('now','start of year','+9 months','weekday 2')

Known limitations




uDate

Description

Returns the year, month, and day from a date in the format YYYY-MM-DD.

NoteRefer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

string uDate([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the date part out of a timestamp:

uDate("now") // returns current date in the form "YYYY-MM-DD".
uDate("now", "start of year", "9 months", "weekday 2")   //returns the date of the first Tuesday in October of this year.



uDateTime

Description

Returns year, month, and day from a date in the format YYYY-MM-DD HH:MM:SS.

NotePlease refer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

string uDateTime([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the datetime part out of a timestamp.

uDateTime("now")  // returns current date in the form "YYYY-MM-DD HH:MM:SS"
uDateTime("now", "start of month", "1 months", "-1 day")   // returns the date of the last day in this month



uDay

Description

Returns the day number of the date specified.

NoteRefer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

string uDay([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the day number out of a timestamp:

uDay("now")  // returns current day number
uDay("1969-03-13 10:22:23.231")   // returns "13"



uDayOfYear

Description

Returns the number of days since the beginning of the year.

Syntax

string uDayOfYear([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the day number out of a timestamp:

uDayOfYear("now")  // returns how many day have already passed this year
uDayOfYear("1969-03-13 10:22:23.231")   // returns "72"



uHour

Description

Returns the hour of the date specified.

NotePlease refer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

string uHour([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

Get the hour from a date.

uHour("now")  // returns current hour
uHour("1969-03-13 10:22:23.231")   // returns "10"



uQuarter

Description

Returns of the year in which a date occurs.

Syntax

string uQuarter([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the hour from a date:

uHour("now")  // returns current quarter
uHour("1969-03-13 10:22:23.231")   // returns "10"



uIsoWeek

Description

Returns the week number as defined by ISO 8601.

The first week of a year is Number 01, which is defined as being the week which contains the first Thursday of the calendar year, which implies that it is also:

The last week of a year, Number 52 or 53, therefore is:

NoteRefer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

number uIsoWeek([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the ISO week number from a date.

uIsoWeek("now")  // returns current week number



uJuliandate

Description

Returns the number of days since noon in Greenwich on November 24, 4714 B.C. in the format DDDD.DDDD. For date and time calculation, the juliandate function is the best choice.

Syntax

string uJuliandate([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To convert a date into a numerical value for calculation.

uJuliandate(‘now’)  // returns current date in the form "DDDD.DDDD"

To compute the number of seconds between two dates:

uJuliandate(‘now’)*86400 - julianday('2004-01-01 02:34:56')*86400

To compute the number of days since the Battle of Hastings:

uJuliandate(‘now’) - uJuliandate('1066-10-14','gregorian')

To compute the date and time given a UNIX timestamp 1092941466, and compensate for your local time zone:

uJuliandate(1092941466, 'unixepoch', 'localtime');



uMinute

Description

Returns the minute of the date specified.

Syntax

string uMinute([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

Get the minute from a date

uMinute("now")  // returns current minute
uMinute("1969-03-13 10:22:23.231")   // returns "22"



uMonth

Description

Returns the month of the date specified.

Syntax

string uMonth([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the month from a date:

uMonth("now")  // returns current month
uMonth("1969-03-13 10:22:23.231")   // returns "03"



uMonthName

Description

Returns the name of month of the date specified in the current locale language.

Syntax

string uMonthName([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the name of month from a date:

uMonthName("now")  // returns current name of month

To set the locale to English:

uSetLocale("English")
uMonthName("1969-03-13 10:22:23.231")   // returns "March"

To set the locale to German:

uSetLocale("German")
uMonthName("1969-03-13 10:22:23.231")   // returns "März"



uMonthNameShort

Description

Returns the short form of the name of month of the date specified in the current locale language.

Syntax

string uMonthNameShort([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the short-form name of month from a date:

uMonthNameShort("now")  // returns current name of month.

To set the locale to English:

uSetLocale("English")
uMonthNameShort("1969-03-13 10:22:23.231")   // returns "Mar"

To set the locale to German:

uSetLocale("German")
uMonthNameShort("1969-03-13 10:22:23.231")   // returns "Mär"



uSeconds

Description

Returns the second of the date specified.

Syntax

string uSeconds([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the second from a date:

uSeconds("now")  // returns current second
uSeconds("1969-03-13 10:22:23.231")   // returns "23"



uTimeDiffMs

Description

Returns the difference between two dates in milliseconds.

Syntax

string uTimeDifMs(date1, date2)

Parameters

string date 1

The older date

string date 2

The more recent date

Examples

Example 1

uTimeDiffMs("18:34:20”, “18:34:21”) // returns 1000 
uTimeDiffMs("18:34:20”, “18:34:21.200”) // returns 1200 



uWeek

Description

Returns the week of the date specified.

NotePlease refer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

string uWeek([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the week from a date:

uWeek("now")  // returns current week
uWeek("1969-03-13 10:22:23.231")   // returns "10"



uWeekday

Description

Returns the week of the date specified. The returned values are from 0 (=sunday) to 6.

NoteRefer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

string uWeekday([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

Get the weekday from a date

uWeekday("now")  // returns current weekday number
uWeekday("1969-03-13 10:22:23.231")   // returns "4" for Thursday



uWeekdayName

Description

Returns the week name of the date specified in the current locale language.

NoteRefer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

string uWeekdayName([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the weekday name from a date:

uWeekdayName("now")  // returns current weekname

To set the locale to English:

uSetLocale("English")
uWeekdayName("1969-03-13 10:22:23.231")   // returns "Thursday"

To set the locale to German:

uSetLocale("German")
uWeekdayName("1969-03-13 10:22:23.231")   // returns "Donnerstag"



uWeekdayNameShort

Description

Returns the short form of the weekname of the date specified in the current locale language.

NoteRefer to the “Working with Dates and Times” section for detailed information about the possible modifier arguments.

Syntax

string uWeekdayNameShort([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

To get the weekday name from a date:

uWeekdayNameShort("now")  // returns current weekname

To set the locale to English:

uSetLocale("English")
uWeekdayNameShort("1969-03-13 10:22:23.231")   // returns "Thu"

To set the locale to German:

uSetLocale("German")
uWeekdayNameShort("1969-03-13 10:22:23.231")   // returns "Don"



uYear

Description

Returns the year of the date specified.

Syntax

string uYear([modifiers])

Parameters

string modifiers (optional)

String specifying a date or date calculation. The default is the now modifier.

Examples

Example 1

Get the year from a date

uYear("now")  // returns current year
uYear("1969-03-13 10:22:23.231")   // returns "1969"