<<<<<<< HEAD formatdatetime | H2 | SQLDoc
Skip to main content

formatdatetime

1. FORMATDATETIME Function

======= formatdatetime | H2 Function | SQLDoc

formatdatetime

1. FORMATDATETIME Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The FORMATDATETIME function in H2 database is used to format a given date or timestamp value into a string representation.

2. Syntax

The syntax for the FORMATDATETIME function in H2 database is as follows:

FORMATDATETIME(dateValue, format)

Arguments

  • dateValue: The date or timestamp value that needs to be formatted. It should be a valid date or timestamp value.
  • format: The format pattern string that defines the desired format for the output string.

Return

  • The FORMATDATETIME function returns a string representation of the given date or timestamp value, formatted according to the specified format pattern.

3. Notes

  • The FORMATDATETIME function in H2 database supports a variety of format patterns to represent different parts of the date and time.
  • The format pattern can include special characters and placeholders to represent the date and time components.
  • It is important to use the correct format pattern to ensure the desired output format.
  • If the input date or timestamp value is NULL, the function will return NULL.

4. Examples

Here are a few examples demonstrating the usage of the FORMATDATETIME function in H2 database:

Example 1 - Formatting a date value:

SELECT FORMATDATETIME(DATE '2022-10-15', 'yyyy-MM-dd') AS formatted_date;

Output:

formatted_date
--------------
2022-10-15

Example 2 - Formatting a timestamp value:

SELECT FORMATDATETIME(TIMESTAMP '2022-10-15 14:30:00', 'yyyy-MM-dd HH:mm:ss') AS formatted_timestamp;

Output:

formatted_timestamp
-------------------
2022-10-15 14:30:00

Example 3 - Formatting a timestamp value with timezone offset:

SELECT FORMATDATETIME(TIMESTAMP '2022-10-15 14:30:00+03:00', 'yyyy-MM-dd HH:mm:ss Z') AS formatted_timestamp;

Output:

formatted_timestamp
-------------------
2022-10-15 14:30:00 +0300
  • PARSEDATE - Parse string to date
  • PARSETIME - Parse string to time
  • FORMATNUMBER - Format a number to a string representation