Date: Difference between revisions

From MemCP
Jump to navigation Jump to search
(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...")
 
(Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<!-- Copyright (C) 2026 Carl-Philip Haensch -->
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
<span id="date"></span>
= Date =
= Date =


The '''Date''' module provides date and time functionality for the SCM programming language. This module includes:
<!-- Generated from MemCP c42e19eba on 2026-08-27; do not edit manually. -->
<div class="mw-message-box mw-message-box-notice">Generated from MemCP commit <code>c42e19eba</code> on 27 August 2026. See [[Full SCM API documentation]].</div>
 
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]].


* '''Current time''': Functions to get the current Unix timestamp (now)
== sql_temporal_output ==
* '''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.
formats a temporal SQL result according to its compiler-tracked declared type


← Back to [[Full SCM API documentation]]
'''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 ===
 
* '''value''' (<code>any</code>)


== now ==
== now ==


returns the unix timestamp
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 ===
 
* '''value''' (<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


'''Parameters:'''
<span id="parameters-2"></span>
=== Parameters ===


''This function has no parameters.''
''This function has no parameters.''


'''Returns:''' <code>int</code>
<span id="returns-2"></span>
=== Returns ===
 
* '''value''' (<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 ===
 
* '''value''' (<code>date</code>)


== parse_date ==
== parse_date ==


parses unix date from a string
parses a date from a string


'''Allowed number of parameters:''' 1–1
'''Allowed number of parameters:''' 1–1


'''Parameters:'''
<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 ===
 
* '''value''' (<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 ===
 
* '''value''' (<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 ===
 
* '''value''' (<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 ===
 
* '''value''' (<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 ===
 
* '''value''' (<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 ===
 
* '''value''' (<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 ===
 
* '''value''' (<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 ===
 
* '''value''' (<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 ===
 
* '''value''' (<code>date</code>)

Latest revision as of 11:59, 28 August 2026


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)