473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Date Calculation to select all data for a week

I need to output data for today and the following week.

Here is what I have:

[PHP]// Get all the data from the table
$result = mysql_query("SELECT * FROM $table where curdate() >= day AND curdate() < DATE_ADD(curdate(),INTERVAL 7 day);")
or die(mysql_error());


// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
}[/PHP]

I have also tried:

[PHP]// Get all the data from the table
$result = mysql_query("SELECT * FROM $table where curdate() >= day AND curdate() < day + 7;")
or die(mysql_error());


// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
}[/PHP]

Both of these only output the data with where day = curdate()

day is set to the date type with the default as 0000-00-00

i have mySQL 4.1.15

once again, I need to output data for today and the following week

thanks
Apr 6 '07 #1
3 5296
Try this query ...

SELECT * from tablename where DATE_FORMAT(fieldname,'%m') <= DATE_FORMAT(CurDATE(),'%m');




Thanks,
Scarlet
Apr 6 '07 #2
That worked to get everything out of the database but how do I then do the AND part - so I get todays info out and then the info for the next 7 days and nothing past the next seven days out?

So today I would want to see 2007-04-06 through 2007-04-13 info

tomorrow I would want to see 2007-04-07 through 2007-04-14 info

etc...

Thanks for the help so far!
Apr 6 '07 #3
Problem Solved!!

[PHP]"SELECT * from $table where day BETWEEN CURDATE() AND DATE_ADD(curdate(),INTERVAL 7 day);"[/PHP]

Thanks for any help!
Apr 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: adam | last post by:
Hi all, I am having a problem with calculating a date. What I am looking to do is get the date of Sunday of this week, then use mktime() to find out other days in the past by subtracting days. ...
2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
4
by: Lynn | last post by:
On a form I have Date_Start Date_End I have a new Date_Start1 Date_End1 which the use inputs. I need to validate that Date_Start1 and...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
5
by: Alicia | last post by:
Yes, but will that skip a week and group by the date for me? I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date ...
5
by: bruce24444 | last post by:
I have a database which assigns warranty claims to people with a main screen showing number of files assigned to each person. The number assigned shows day, week, month and year numbers so they can...
1
osward
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >=...
1
by: assgar | last post by:
Hi I need help. I know what I want to accomplish, but I do not know how to do it. WHAT I NEED HELP ACCOMPLISHING: How to do I insert data into a table for a date range of...
1
by: Jonathan Wood | last post by:
I have a GridView control that displays the data in a List<object; My GridView contains the following in its definition: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.