简体   繁体   中英

how to display the day on which a user born in mysql?

I want to display the day on which a user born. I have date-of-birth column in my table in date Format . So please let me know the solution for the problem. I tried myself, then I tried to get it over internet, but got several results for other database like oracle and sqlserver, so please let me know how to get it .

Thanks in advance..!

You can use DATE_FORMAT with %w or %W:

DATE_FORMAT('2012-12-27', '%w');
  • %W = Weekday name (Sunday..Saturday)
  • %w = Day of the week (0=Sunday..6=Saturday)

Use EXTRACT() function

select  
     EXTRACT(YEAR FROM BirthDate), 
     EXTRACT(MONTH FROM BirthDate), 
     EXTRACT(DAY FROM BirthDate) 
from t

Try this:

SELECT DAYNAME('2012-12-27');

Output

Thursday

if you name of day then use :-

 SELECT DAYNAME('2007-02-03');

or if want day of week then use

SELECT DAYOFWEEK('2012-12-27);

for more detail visit:-

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_dayname

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM