Date: Difference between revisions
(Created page with "= 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 docume...") |
No edit summary |
||
| Line 9: | Line 9: | ||
← Back to [[Full SCM API documentation]] | ← 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 | |||
<span id="parameters"></span> | |||
=== Parameters === | |||
* '''value''' (<code>any</code>): type-flexible temporal value | |||
* '''sql_type''' (<code>string</code>): declared SQL temporal type | |||
<span id="returns"></span> | |||
=== Returns === | |||
<code>any</code> | |||
== now == | == now == | ||
returns the | returns the current date/time | ||
'''Allowed number of parameters:''' 0–0 | |||
<span id="parameters-1"></span> | |||
=== Parameters === | |||
''This function has no parameters.'' | |||
<span id="returns-1"></span> | |||
=== Returns === | |||
<code>date</code> | |||
== nanotime == | |||
returns a monotonic nanosecond timestamp for benchmarking (not wall-clock) | |||
'''Allowed number of parameters:''' 0–0 | '''Allowed number of parameters:''' 0–0 | ||
<span id="parameters-2"></span> | |||
=== Parameters === | |||
''This function has no parameters.'' | ''This function has no parameters.'' | ||
''' | <span id="returns-2"></span> | ||
=== Returns === | |||
<code>int</code> | |||
== current_date == | |||
returns the current date (midnight in session timezone) | |||
'''Allowed number of parameters:''' 0–0 | |||
<span id="parameters-3"></span> | |||
=== Parameters === | |||
''This function has no parameters.'' | |||
<span id="returns-3"></span> | |||
=== Returns === | |||
<code>date</code> | |||
== parse_date == | == parse_date == | ||
parses | parses a date from a string | ||
'''Allowed number of parameters:''' 1–1 | '''Allowed number of parameters:''' 1–1 | ||
<span id="parameters-4"></span> | |||
=== Parameters === | |||
* '''value''' (<code>string</code>): values to parse | * '''value''' (<code>string</code>): values to parse | ||
'''Returns:''' <code>int</code> | <span id="returns-4"></span> | ||
=== Returns === | |||
<code>date</code> | |||
== format_date == | |||
formats a unix timestamp, date, or datetime string into a date string | |||
'''Allowed number of parameters:''' 2–2 | |||
<span id="parameters-5"></span> | |||
=== Parameters === | |||
* '''timestamp''' (<code>any</code>): unix timestamp, date, or datetime string | |||
* '''format''' (<code>string</code>): MySQL-style format string (e.g. %Y-%m-%d %H:%i:%s) | |||
<span id="returns-5"></span> | |||
=== Returns === | |||
<code>string</code> | |||
== 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 | |||
<span id="parameters-6"></span> | |||
=== Parameters === | |||
* '''value''' (<code>any</code>): date value | |||
* '''field''' (<code>string</code>): field name: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, QUARTER, WEEK, DAYOFWEEK, WEEKDAY | |||
<span id="returns-6"></span> | |||
=== Returns === | |||
<code>int</code> | |||
== date_add == | |||
adds an interval to a date value | |||
'''Allowed number of parameters:''' 3–3 | |||
<span id="parameters-7"></span> | |||
=== Parameters === | |||
* '''value''' (<code>any</code>): date value | |||
* '''amount''' (<code>int</code>): interval amount | |||
* '''unit''' (<code>string</code>): interval unit: DAY, WEEK, MONTH, YEAR, HOUR, MINUTE, SECOND | |||
<span id="returns-7"></span> | |||
=== Returns === | |||
<code>date</code> | |||
== date_sub == | |||
subtracts an interval from a date value | |||
'''Allowed number of parameters:''' 3–3 | |||
<span id="parameters-8"></span> | |||
=== Parameters === | |||
* '''value''' (<code>any</code>): date value | |||
* '''amount''' (<code>int</code>): interval amount | |||
* '''unit''' (<code>string</code>): interval unit: DAY, WEEK, MONTH, YEAR, HOUR, MINUTE, SECOND | |||
<span id="returns-8"></span> | |||
=== Returns === | |||
<code>date</code> | |||
== date_trunc_day == | |||
truncates a datetime to date (midnight UTC) | |||
'''Allowed number of parameters:''' 1–1 | |||
<span id="parameters-9"></span> | |||
=== Parameters === | |||
* '''value''' (<code>any</code>): date/datetime value | |||
<span id="returns-9"></span> | |||
=== Returns === | |||
<code>date</code> | |||
== timestampdiff == | |||
returns the difference between two datetimes in the given unit | |||
'''Allowed number of parameters:''' 3–3 | |||
<span id="parameters-10"></span> | |||
=== Parameters === | |||
* '''unit''' (<code>string</code>): SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | |||
* '''dt1''' (<code>any</code>): first datetime | |||
* '''dt2''' (<code>any</code>): second datetime | |||
<span id="returns-10"></span> | |||
=== Returns === | |||
<code>int</code> | |||
== datediff == | |||
returns number of days between two dates (date1 - date2) | |||
'''Allowed number of parameters:''' 2–2 | |||
<span id="parameters-11"></span> | |||
=== Parameters === | |||
* '''date1''' (<code>any</code>): first date | |||
* '''date2''' (<code>any</code>): second date | |||
<span id="returns-11"></span> | |||
=== Returns === | |||
<code>int</code> | |||
== str_to_date == | |||
parses a string with MySQL format specifiers to a date | |||
'''Allowed number of parameters:''' 2–2 | |||
<span id="parameters-12"></span> | |||
=== Parameters === | |||
* '''value''' (<code>string</code>): date string | |||
* '''format''' (<code>string</code>): MySQL format string (e.g. %Y-%m-%d) | |||
<span id="returns-12"></span> | |||
=== Returns === | |||
<code>date</code> | |||
Revision as of 08:11, 27 August 2026
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