-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;
1
  • use DATE(date) Commented Jun 6, 2017 at 8:51

4 Answers 4

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

see the date_format documentation to see all the possible formats

Sign up to request clarification or add additional context in comments.

5 Comments

Its working. Thanks!
Someone that actually read the question +1
if i want to display data from date & month?? SELECT * FROM tbl_name WHERE dob = '-06-06';
SELECT * FROM tbl_name WHERE DATE_FORMAT(dob, '-%m-%d') = '-06-06'
Thank you Eduard!
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

Comments

0
select month('2017-06-15'),DAY('2017-06-15')

1 Comment

Please explain your answer code on it's own is useless explain how it helps the OP with there problem.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.