Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old November 5th, 2003, 07:44 AM
kathiramu kathiramu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 kathiramu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql query to find weekends within two dates

hi,
i need help in writing a query to find the number of saturdays and sundays falling within a time period(two dates).
thnks
ramu

Reply With Quote
  #2  
Old November 5th, 2003, 01:20 PM
aj2taylo aj2taylo is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mississauga, ON, Canada
Posts: 61 aj2taylo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 sec
Reputation Power: 2
Send a message via ICQ to aj2taylo Send a message via AIM to aj2taylo Send a message via Yahoo to aj2taylo
RE: mysql query to find weekends within two dates

What are your dates stored as? Timestamp? Date?

Reply With Quote
  #3  
Old November 5th, 2003, 01:35 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: mysql query to find weekends within two dates

I'm not quite sure what you are asking. Are you try to find the number of Saturdays and Sundays between two dates, or trying to find the number of Saturdays and Sundays that are stored in some table in a database between two dates.

If it's the first one, do it in PHP, not MySQL.

If it's the second one, try this:
Code:
SELECT COUNT(*) FROM table_name
WHERE date_column BETWEEN '2003-10-01' AND '2003-11-01'
AND WEEKDAY(date_column) > 4

Reply With Quote
  #4  
Old November 5th, 2003, 10:54 PM
kathiramu kathiramu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 kathiramu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: mysql query to find weekends within two dates

hi,
i am happy to see the reply to my posting here.
1. i am using Date filed to store dates.
2. i am trying find the number of Saturdays and Sundays between two dates stored in a table.
thanks.
ramu

Reply With Quote
  #5  
Old November 10th, 2003, 04:08 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: mysql query to find weekends within two dates

How about this? There may be a way of achieving the same result in a shoter way.

php Code:
Original - php Code
  1. <?php   
  2. $fromDate='10/1/2003'; // Start of date range
  3. $toDate='11/30/2003'; // End of date range
  4.  
  5. $arrFrom=explode('/',$fromDate);
  6. $arrTo=explode('/',$toDate);
  7.  
  8. $numSundays=0;
  9. $numSaturdays=0;
  10.  
  11. $fromDate=mktime(0,0,0,$arrFrom[0],$arrFrom[1],$arrFrom[2]);
  12. $toDate=mktime(0,0,0,$arrTo[0],$arrTo[1],$arrTo[2])+(60*60*24);
  13. while($fromDate<>$toDate)
  14. {
  15.     if(date("w",$fromDate)==0)  $numSundays++;
  16.     else if(date("w",$fromDate)==6) $numSaturdays++;
  17.     $fromDate=$fromDate+(60*60*24);
  18. }
  19.  
  20. echo "There are <b>$numSundays</b> Sundays and <b>$numSaturdays</b> Saturdays between given date range.";
  21. ?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > mysql query to find weekends within two dates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway