STR_TO_DATE_TIME()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Parses a string argument using the supplied format and returns a TIME
or DATETIME
value.
USAGE
STR_TO_DATE_TIME(string, format)
Argument Name | Description |
---|---|
| The string to parse |
| A specification of how to parse the data out of the string |
DETAILS
STR_TO_DATE_TIME()
is a date-time function that converts a string into a time value based on a restricted parsing order specified in the format
argument.
Spaces specified in the string and the format are matched loosely, while other non-escape characters in the format string are required to exist in the source string.
A NULL
is returned if any argument is NULL
.
Option | Description |
---|---|
| Microseconds (6 digits) |
| Hour in 2 digits (00-23) |
| Hour in 2 digits (01-12) |
| Hour in 2 digits (01-12) |
| Minute in 2 digits |
| Hour in 1 to 2 digits (0-23) |
| Hour in 1 to 2 digits (1-12) |
| AM or PM according to the current locale |
| An alias for |
| Seconds in 2 digits |
| Seconds in 2 digits |
| An alias for "%H:%i:%S" |
| A literal |
EXAMPLES
SELECT STR_TO_DATE_TIME('12,34,56', '%h,%i,%s') AS result;
+-----------------+
| result |
+-----------------+
| 12:34:56.000000 |
+-----------------+
SELECT STR_TO_DATE_TIME('September 1, 2019 11:30',
'%M %d,%Y %h:%i') AS result;
+-----------------+
| result |
+-----------------+
| 11:30:00.000000 |
+-----------------+
SELECT STR_TO_DATE_TIME('01,02,2020', '%d,%m,%Y') AS result;
+-----------------+
| result |
+-----------------+
| 00:00:00.000000 |
+-----------------+