i have a table of adds in my database and i define a field date with each record which has a type of varchar and srores date in date format. i insert value in date field by using now() function and my date field has value in format
2012-10-07 14:00:54
i want to fetch the records matching by date of today,yesterday,last week and last month but i dont know how to do this. i searched on google alot and i tried many functions but its not working i run the following queries
select * from adds where date(date_sub(now(), interval 0 day))
select * from adds where date(date_sub(now(), interval 1 day))
select * from adds where date(date_sub(now(), interval 7 day))
select * from adds where date(date_sub(now(), interval 31 day))
all these are not working and i also tried
select * from adds where date=curdate()
select * from adds where date=current_date()
please guide me how can i fetch records.
i am using localhost server xampp win32 1.7.7
Then you need to
SELECTthose records where the date is between the bounds:The above ought to give you last week, ending at today’s beginning at 00:00.
Note: the above works if the varchar date syntax is the same as MySQL. If it is not, you need to specifically instruct MySQL as how to parse it:
See
date_format()for the date format syntax.