STR_TO_DATE_TIME()

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

string

The string to parse

format

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

%f

Microseconds (6 digits)

%H

Hour in 2 digits (00-23)

%h

Hour in 2 digits (01-12)

%I

Hour in 2 digits (01-12)

%i

Minute in 2 digits

%k

Hour in 1 to 2 digits (0-23)

%l

Hour in 1 to 2 digits (1-12)

%p

AM or PM according to the current locale

%r

An alias for %I:%i:%S %p

%S

Seconds in 2 digits

%s

Seconds in 2 digits

%T

An alias for "%H:%i:%S"

%%

A literal % character

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

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 |
+-----------------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES