Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 21st, 2008, 6:06 PM   #1
Robocop
Programmer
 
Join Date: Sep 2004
Posts: 44
Rep Power: 0 Robocop is on a distinguished road
MSSQL - Get data between specific week days

Hello:

I need help in how to get data from a table with a daterange from sunday to saturday of the last week.

What I'm looking for is to be able to do this any day of the current week.
Robocop is offline   Reply With Quote
Old Jun 21st, 2008, 9:43 PM   #2
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 256
Rep Power: 2 Jabo is on a distinguished road
Re: MSSQL - Get data between specific week days

From the day you're on, just go back to the previous Sunday, make an array of 7 dates, starting at that Sunday, include the next 7 days in your array, see if today is in that array, if it is, go back another Sunday and start again, if it isn't, then you have your week.
Jabo is offline   Reply With Quote
Old Jun 23rd, 2008, 7:02 AM   #3
MickeySoFine1972
Software Developer
 
MickeySoFine1972's Avatar
 
Join Date: Jun 2008
Posts: 4
Rep Power: 0 MickeySoFine1972 is on a distinguished road
Re: MSSQL - Get data between specific week days

I think you will need something like this:
function GetRowsWeekLeeadingUptoDate($a_Date)      {
    $a_SevenDaysAgo = $a_Date - days(7);
    $l_Sql = "SELECT * FROM table_name WHERE date BETWEEN $a_Date AND $a_SevenDaysAgo;";
    $l_Results = mysql_query($l_Sql);
    return $l_Results;
}

depending on how your storing you dates you will need to convert between the formats to pass to you sql for the BETWEEN part

Mike
__________________
There are 10 kinds of people in this world....Those who understand binary and those who don't.
MickeySoFine1972 is offline   Reply With Quote
Old Jun 24th, 2008, 5:54 AM   #4
MiKuS
Programmer
 
Join Date: Jun 2007
Posts: 99
Rep Power: 2 MiKuS is on a distinguished road
Re: MSSQL - Get data between specific week days

on that note i had real headaches working with time based queries, it's easier to use a timestamp and convert your times from that.
MiKuS is offline   Reply With Quote
Old Jun 24th, 2008, 6:01 AM   #5
MickeySoFine1972
Software Developer
 
MickeySoFine1972's Avatar
 
Join Date: Jun 2008
Posts: 4
Rep Power: 0 MickeySoFine1972 is on a distinguished road
Re: MSSQL - Get data between specific week days

Quote:
Originally Posted by MiKuS View Post
on that note i had real headaches working with time based queries, it's easier to use a timestamp and convert your times from that.
I agree

its a shame that sort of thing isnt built into the php5_mysql module, or is it?

Mike
__________________
There are 10 kinds of people in this world....Those who understand binary and those who don't.
MickeySoFine1972 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question regarding data input into PHP/Mysql using something other than GET davil PHP 6 Nov 20th, 2007 8:06 AM
caluculate day of week given present date and number of days srinivasc_it C++ 4 Nov 4th, 2006 4:54 AM
convert unarrenged .txt data to arrange .txt data pastalover Visual Basic 2 Jun 23rd, 2006 4:22 PM
Recommended Practice for returning data from function Arla C# 1 Aug 16th, 2005 12:21 PM
help with sockets, having a client recieve data as well as send. cypherkronis Python 7 Jul 1st, 2005 5:59 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:53 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC