相关文章推荐
潇洒的茴香  ·  Date.prototype.toUTCSt ...·  4 月前    · 
道上混的饭盒  ·  Get-Date ...·  1 月前    · 
冷静的热带鱼  ·  【jdk1.8】LocalDateTime ...·  1 月前    · 
瘦瘦的棒棒糖  ·  单位简介·  10 月前    · 
冲动的显示器  ·  Constraint streams ...·  2 年前    · 
Skip to main content
Version: Latest-4.0

str_to_date

Converts a string into a DATETIME value according to the specified format. If the conversion fails, NULL is returned.

The format must be consistent with that described in date_format .

This function is inverse to date_format .

Syntax

DATETIME STR_TO_DATE(VARCHAR str, VARCHAR format)

Parameters

str : the time expression you want to convert. It must be of the VARCHAR type.

format : the format used to return the value. For the supported format, see date_format .

Return value

Returns a value of the DATETIME type. If format specifies a date, a DATE value is returned.

NULL is returned if str or format is NULL.

Examples

Example 1: Convert the input into a DATETIME value.

MySQL > select str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s');
+---------------------------------------------------------+
| str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s') |
+---------------------------------------------------------+
| 2014-12-21 12:34:56 |
+---------------------------------------------------------+