Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This is not a web development question, but I know you guys deal with queries more than anyone.
Using SQL, is it possible to have a query pull the dates of the first days of each week between two dates? For example, I want to pull the dates of the Sundays between 1/2/2005 and 1/30/2005:
1/2/2005
1/9/2005
1/16/2005
1/23/2005
1/30/2005Is there a way?

it depends on how you stored the timestamp. for example, if you stored them as a unix timestamp, it would be hard, because your query line would involve a lot of math. The way i would do it (probably not the most efficient,) would be to have two columns of times, with different formats. so for example, you could have a column named unix_time and it would contain a number coresponding to the unix timestamp of that entry, and then another column named dayofweek_time, which would contain the abbriviation of the week (Sun, Mon, Tue...etc...)
if you could do that, your query would be something like
"SELECT * FROM `table` WHERE (`unix_time` > '$start_date' && `unix_time` < '$end_date' && `dayofweek_time` = 'Sun'"$start_date would be the unix timestamp equivilent of your beggining date, and $end_date would be the end. other than that, im sure there are other ways...but i really think it depends on the time format you have them stored as.
good luck

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |