Date

From MemCP
Revision as of 11:59, 28 August 2026 by Wikiservice (talk | contribs) (Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Date

Generated from MemCP commit c42e19eba on 27 August 2026. See Full SCM API documentation.

The Date module handles SQL temporal values and Scheme date computations. It includes:

  • current date and time values;
  • parsing and MySQL-compatible formatting;
  • field extraction and truncation;
  • interval addition and subtraction;
  • differences between dates or timestamps;
  • compiler-aware conversion to the declared SQL temporal output type.

Timezone conversion and UTC/session-zone helpers are documented separately under Timezone.

sql_temporal_output

formats a temporal SQL result according to its compiler-tracked declared type

Allowed number of parameters: 2–2

Parameters

  • value (any): type-flexible temporal value
  • sql_type (string): declared SQL temporal type

Returns

  • value (any)

now

returns the current date/time

Allowed number of parameters: 0–0

Parameters

This function has no parameters.

Returns

  • value (date)

nanotime

returns a monotonic nanosecond timestamp for benchmarking (not wall-clock)

Allowed number of parameters: 0–0

Parameters

This function has no parameters.

Returns

  • value (int)

current_date

returns the current date (midnight in session timezone)

Allowed number of parameters: 0–0

Parameters

This function has no parameters.

Returns

  • value (date)

parse_date

parses a date from a string

Allowed number of parameters: 1–1

Parameters

  • value (string): values to parse

Returns

  • value (date)

format_date

formats a unix timestamp, date, or datetime string into a date string

Allowed number of parameters: 2–2

Parameters

  • timestamp (any): unix timestamp, date, or datetime string
  • format (string): MySQL-style format string (e.g. %Y-%m-%d %H:%i:%s)

Returns

  • value (string)

extract_date

extracts a date field (YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, QUARTER, WEEK, DAYOFWEEK, WEEKDAY) from a date value

Allowed number of parameters: 2–2

Parameters

  • value (any): date value
  • field (string): field name: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, QUARTER, WEEK, DAYOFWEEK, WEEKDAY

Returns

  • value (int)

date_add

adds an interval to a date value

Allowed number of parameters: 3–3

Parameters

  • value (any): date value
  • amount (int): interval amount
  • unit (string): interval unit: DAY, WEEK, MONTH, YEAR, HOUR, MINUTE, SECOND

Returns

  • value (date)

date_sub

subtracts an interval from a date value

Allowed number of parameters: 3–3

Parameters

  • value (any): date value
  • amount (int): interval amount
  • unit (string): interval unit: DAY, WEEK, MONTH, YEAR, HOUR, MINUTE, SECOND

Returns

  • value (date)

date_trunc_day

truncates a datetime to date (midnight UTC)

Allowed number of parameters: 1–1

Parameters

  • value (any): date/datetime value

Returns

  • value (date)

timestampdiff

returns the difference between two datetimes in the given unit

Allowed number of parameters: 3–3

Parameters

  • unit (string): SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
  • dt1 (any): first datetime
  • dt2 (any): second datetime

Returns

  • value (int)

datediff

returns number of days between two dates (date1 - date2)

Allowed number of parameters: 2–2

Parameters

  • date1 (any): first date
  • date2 (any): second date

Returns

  • value (int)

str_to_date

parses a string with MySQL format specifiers to a date

Allowed number of parameters: 2–2

Parameters

  • value (string): date string
  • format (string): MySQL format string (e.g. %Y-%m-%d)

Returns

  • value (date)