tags:

views:

20

answers:

1

How to select a day say thursday from a date in the mysql select query and use this day to select some other values in same table

select id,music_id,contest_no,today,exp_date,start_hour,start_minute,start_ampm, DAYNAME(today) as chday
from hit_music_content
where
    exp_date>='2010-07-30' and 
    today between '2010-07-30' and '2010-08-05'
limit 0,5

I want if this query is true then select all the values from hit_music_content on some day say friday but How?

A: 

have a look at date_format in mysql http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

%w selects a day as int (where 0 is sunday) %W selects a day as text (Sunday).

SELECT DATE_FORMAT(YOURDATEFIELD,'%W') as dataformated FROM YOURTABLE;
Tim
select id,music_id,contest_no,today,exp_date,start_hour,start_minute,start_ampm, DAYNAME(today) as chday from hit_music_content where exp_date>='2010-07-30' and today between '2010-07-30' and '2010-08-05' limit 0,5i want if this query is true then select all the values from hit_music_content on some day say friday but How
anuradha
is today a date field? now your just selecting which day it is. If you want to select all events on a certain day you've to use an extra AND statement AND DAYNAME(today) = 'friday'
Tim
thanx but i want to select all record as exp_date>='2010-07-30' and today between '2010-07-30' and '2010-08-05' and till friday record after friday will be changes
anuradha