-1

I want to get date & month from date. example 2017-06-15 so I want date & month i.e. -06-15. Do u have any idea? Really appreciated.

From Below query I am getting month from date. but I want both date & month

SELECT MONTHNAME(`date`) AS month_name FROM table_name;
Pradnya
  • 16
  • 4

4 Answers4

2
SELECT DATE_FORMAT(date, '-%m-%d') AS month_name FROM table_name;

see the date_format documentation to see all the possible formats

Eduard Void
  • 2,646
  • 1
  • 13
  • 13
0

MySQL MONTH() returns the MONTH for the date within a range of 1 to 12 ( January to December). It Returns 0 when MONTH part for the date is 0.

SELECT MONTH('2009-05-18'); 

MySQL DAY() returns the day of the month for a specified date. The day returned will be within the range of 1 to 31. If the given date is ‘0000-00-00’, the function will return 0. The DAYOFMONTH() is the synonym of DAY().

SELECT DAY('2008-05-15'); 

Link : here

0
select month('2017-06-15'),DAY('2017-06-15')
ManiMuthuPandi
  • 1,594
  • 2
  • 26
  • 46
0

you can use this function

DATEPART(datepart,date)

use below query

SELECT DATEPART(yyyy,datecolumn) AS dateYear,
DATEPART(mm,datecolumn) AS dateMonth,
DATEPART(dd,datecolumn) AS dateDay
FROM table_name
Kruti Aparnathi
  • 175
  • 1
  • 11