Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
|
I moved this to the DB forum, as I see it more related to this field.
Assuming that your DB is mysql, look at this page for a list of the date/time related functions in mysql 5+
http://dev.mysql.com/doc/refman/5.1/...functions.html
All the queries below are based on a table named tableX with a datetime or timestamp type field named "dtmY".
All of july:
Code:
select * from tableX where date(dtmY) between '2009-07-01' and '2009-07-31'
or
Code:
select * from tableX where extract(year of dtmY)=2009 and extract(month from dtmY)=7
for last week (of a month):
Code:
select * from tableX where yearweek(dtmY) = yearweek('2009-08-01' - interval 1 day)
Here, we work with the week nbr for a given month.
This should get every rows of the last week of july 2009 (starting from august 01 minus 1 day)
For last week (today - 1 week):
Deriving last query
Code:
select * from tableX where yearweek(dtmY) = yearweek(now()- interval weekday(now()-interval 1 day) day)
for this day one year ago
Code:
select * from tableX where date(dtmY)=now()-interval 1 year
for between the 17-21 of august;
Code:
select * from tableX where date(dtmY) between '2009-08-17' and '2009-08-21'
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 08-10-2009 at 07:12 PM..
|