Computing.Net > Forums > Web Development > SQL Query - First Day of Each Week

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

SQL Query - First Day of Each Week

Reply to Message Icon

Name: Chad Johnson (by ChadJohnson)
Date: January 4, 2005 at 17:54:08 Pacific
OS: n/a
CPU/Ram: n/a
Comment:

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/2005

Is there a way?



Sponsored Link
Ads by Google

Response Number 1
Name: nexterday
Date: January 9, 2005 at 08:30:03 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: SQL Query - First Day of Each Week

SQL query with HTML link www.computing.net/answers/webdevel/sql-query-with-html-link/319.html

php, jpgraph labels x-axis www.computing.net/answers/webdevel/php-jpgraph-labels-xaxis/599.html

My site needs some color... www.computing.net/answers/webdevel/my-site-needs-some-color/2632.html