Pakaphol Buathon
Pakaphol Buathon

Reputation: 188

Convert abbreviated month name to number within single line

Hi all I am very new to mysql statement I just wondering how do we convert and get only Abbreviated month name to number with single code Example String "2008Jan20" to 2008-01-20 Then get only month 01

 MONTH(STR_TO_DATE(6, '%m'));

Upvotes: 1

Views: 940

Answers (1)

Abhishek Sharma
Abhishek Sharma

Reputation: 6661

use str_to_date converts the string into a date value based on the format string

str_to_date('2008Jan20','%Y%b%d')

Get month number

 Month(str_to_date('2008Jan20','%Y%b%d')) //get month number 

Get MONTHNAME

MONTHNAME(str_to_date('2008Jan20','%Y%b%d')) //get month name 

Upvotes: 1

Related Questions