MySQL Date/Time str_to_date() Function

The str_to_date() is a MySQL date/time function. It is used to convert the string into given format_mask.

Syntax

Parameter:

String : string value to get date

format_mask : format to be applied, following are the different formats.

ValueDescription
%aWeekday name abbreviated (Sun to Sat)
%bMonth name abbreviated (Jan to Dec)
%cMonth as a numeric value (0 to 12)
%DDay of the month as a numeric value, followed by suffix (1st, 2nd, 3rd, ...)
%dDay of the month as a numeric value (01 to 31)
%eDay of the month as a numeric value (0 to 31)
%fMicroseconds (000000 to 999999)
%HHour (00 to 23)
%hHour (00 to 12)
%IHour (00 to 12)
%iMinutes (00 to 59)
%jDay of the year (001 to 366)
%kHour (00 to 23)
%lHour (1 to 12)
%MMonth name in full (January to December)
%mMonth name as a numeric value (00 to 12)
%pAM or PM
%rTime in 12 hour AM or PM format (hh:mm:ss AM/PM)
%SSeconds (00 to 59)
%sSeconds (00 to 59)
%TTime in 24 hour format (hh:mm:ss)
%UWeek where Sunday is the first day of the week (00 to 53)
%uWeek where Monday is the first day of the week (00 to 53)
%VWeek where Sunday is the first day of the week (01 to 53)
Available starting in MySQL 3.23.8 and used with %X
%vWeek where Monday is the first day of the week (01 to 53)
Available starting in MySQL 3.23.8 and used with %X
%WWeekday name in full (Sunday to Saturday)
%wDay of the week where Sunday=0 and Saturday=6
%XYear for the week where Sunday is the first day of the week
Available starting in MySQL 3.23.8 and used with %V
%xear for the week where Monday is the first day of the week
Available starting in MySQL 3.23.8 and used with %v
%YYear as a numeric, 4-digit value
%yYear as a numeric, 2-digit value

Returns:

This function returns a date specified by a format mask.

Example 1

Output:


MySQL Datetime str_to_date() Function

Example 2

Output:


MySQL Datetime str_to_date() Function
Next TopicMySQL datetime




Latest Courses