Date

From MemCP
Revision as of 08:11, 27 August 2026 by Carli (talk | contribs)
Jump to navigation Jump to search

Date

The Date module provides date and time functionality for the SCM programming language. This module includes:

  • Current time: Functions to get the current Unix timestamp (now)
  • Date parsing: Functions to parse date strings into Unix timestamps (parse_date)

These functions provide essential tools for working with dates and timestamps in SCM programs, enabling time-based operations and date string processing.

← Back to Full SCM API documentation


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

any

now

returns the current date/time

Allowed number of parameters: 0–0

Parameters

This function has no parameters.

Returns

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

int

current_date

returns the current date (midnight in session timezone)

Allowed number of parameters: 0–0

Parameters

This function has no parameters.

Returns

date

parse_date

parses a date from a string

Allowed number of parameters: 1–1

Parameters

  • value (string): values to parse

Returns

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

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

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

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

date

date_trunc_day

truncates a datetime to date (midnight UTC)

Allowed number of parameters: 1–1

Parameters

  • value (any): date/datetime value

Returns

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

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

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

date