Date and Time

Most 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").

See also




Time Strings

Description

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

NoteNote 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.

Examples

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

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



Modifiers

Description

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.

  6. NNN years

  7. start of month

  8. start of year

  9. start of day

  10. weekday N

  11. unixepoch

  12. localtime

  13. utc

Examples

Example 1

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 9) shift the date backwards to the beginning of the current month, year, or day.

The “weekday” (10) 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 (11) 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 (12) adjusts the previous time string so that it displays the correct local time. utc undoes this.




Date and time calculations

Description

These examples show you some typical date and time calculations.

Examples

Example 1

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

uFormatDate ('%s','now')

Compute the number of seconds between two dates

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

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

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



Known limitations

Description

The computation of local time varies by locale. In this implementation, the standard C library function localtime() is used to assist in the calculation of local time. Also, the localtime() C function normally only works for years between 1970 and 2037. For dates outside this range, we attempt to map the year into an equivalent year within this range, do the calculation, then map the year back.




Date and time function list

Description

This table lists all the date and time functions.

Function

Description

uDate

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

uDateTime

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

uDay

Returns the day number of the date specified

uDayOfYear

Returns the number of days since the beginning of the year

uHour

Returns the hour of the date specified

uQuarter

Returns the quarter of the year

uIsoWeek

Returns the week number defined by ISO 8601

uJuliandate

Returns the number of days since noon in Greenwich on November 24, 4714 B.C. in the format DDDD.DDDD

uMinute

Returns the minute of the date specified

uMonth

Returns the month of the name specified

uMonthName

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

uMonthNameShort

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

uSeconds

Returns the second of the date specified

uTime

Returns the time part from a date in the format HH.MM.SS

uTimeDiffMs

Returns the difference between two dates in milliseconds

uWeek

Returns the week of the date specified

uWeekday

Returns the weekday of the date specified

uWeekdayName

Returns the weekday name of the date specified in the current locale language

uWeekdayNameShort

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

uYear

Returns the year of the date specified

NoteRefer to “Date and Time” for detailed information about the possible modifier arguments.




uDate

Description

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

Syntax

string uDate([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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 this
year.



uDateTime

Description

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

Syntax

string uDateTime([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

Get the datetime part from 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

Syntax

string uDay([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

Get the day number out of a timestamp

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



uHour

Description

Returns the hour of the date specified

Syntax

string uHour([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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



uQuarter

Description

Returns the quarter of the year

Syntax

string uQuarter([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

uQuarter ("now") // returns current quarter
uQuarter ("2005-03-13 10:22:23.231") // returns "1"



uIsoWeek

Description

Returns the week number 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:

Syntax

number uIsoWeek([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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)

List of strings specifying a date or date calculation. Default is the "now" modifier.

Examples

Example 1

Convert a date into a numerical value for calculation

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

Compute the number of seconds between two dates

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

Compute the number of days since the battle of Hastings

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

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

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



uMinute

Description

Returns the minute of the date specified

Syntax

string uMinute([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

To get the name of month from a date

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

Setting the locale to English

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

Setting 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)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

Get the name of month from a date

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

Setting the locale to English

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

Setting 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)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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



uTime

Description

Returns the time part from a date in the format HH.MM.SS.

Syntax

string uTime([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

Get the time part from a timestamp

uTime() // returns current UTC time
uTime("now","localtime") // returns current local time



uTimeDiffMs

Description

Returns the difference between two dates in milliseconds

Syntax

string uTimeDiffMs(date1, date2)

Parameters

string date1

The older date

string date2

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

Syntax

string uWeek([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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



uWeekday

Description

Returns the weekday number of the date specified

Syntax

string uWeekday([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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



uWeekdayName

Description

Returns the weekday name of the date specified in the current locale language

Syntax

string uWeekdayName([modifiers]);

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

uWeekdayName("now") // returns current weekday name

Setting the locale to English

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

Setting the locale to German

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



uWeekdayNameShort

Description

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

Syntax

string uWeekdayNameShort([modifiers])

Parameters

string modifiers (optional)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

uWeekdayNameShort("now") // returns current weekday name

Setting the locale to English

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

Setting 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)

List of strings specifying a date or date calculation. Default is the now modifier.

Examples

Example 1

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