parsedatetime
1. PARSEDATETIME Function
=======parsedatetime
1. PARSEDATETIME Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe PARSEDATETIME function in H2 database is used to parse a string representation of a date and time into a DateTime data type.
2. Syntax
The syntax for the PARSEDATETIME function in H2 database is as follows:
PARSEDATETIME(string, pattern)
Arguments
string
: The string representing the date and time that needs to be parsed.pattern
: The pattern specifying the format of the input string.
Return
- The PARSEDATETIME function returns a DateTime value representing the parsed date and time.
3. Notes
- The PARSEDATETIME function in H2 database uses the pattern to identify the format of the input string. It is important to provide the correct pattern that matches the input string format.
- If the input string does not match the specified pattern, the PARSEDATETIME function will return
NULL
. - H2 database supports a variety of format patterns to parse different parts of the date and time. Refer to the H2 database documentation for a complete list of supported patterns.
4. Examples
Here are a few examples demonstrating the usage of the PARSEDATETIME function in H2 database:
Example 1 - Parsing a date and time string:
SELECT PARSEDATETIME('2022-03-15 09:30:00', 'yyyy-MM-dd HH:mm:ss') AS parsed_datetime;
Output:
parsed_datetime
------------------------
2022-03-15 09:30:00.0
Example 2 - Parsing a date string with a custom format:
SELECT PARSEDATETIME('15-03-2022', 'dd-MM-yyyy') AS parsed_date;
Output:
parsed_date
------------
2022-03-15
Example 3 - Parsing a time string:
SELECT PARSEDATETIME('18:45:30', 'HH:mm:ss') AS parsed_time;
Output:
parsed_time
-------------------
1970-01-01 18:45:30
5. Related Functions
- formatdatetime - Format a DateTime value as a string
- NOW - Get the current DateTime