Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-23-2005, 10:55 AM Select... Between
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Hi everyone.

I am trying to construct a SELECT statement that calls data inbetween and including 2 dates.

At the moment, i am doing this

PHP Code:
SELECT WHERE date BETWEEN '$from_date' AND '$to_date' 
But i have just realised that from_date and to_date data are not included within this statement.

Does anyone know how to call all the data inbetween two dates and include those dates as well?

Thanks in advance.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
 
Register now for full access!
Old 05-23-2005, 11:02 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
How do you call mysql_query() with that? Please provide the exact piece of code, not the variable string only.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-23-2005, 11:46 AM
Marvin Le Rouge's Avatar
Skilled Talker

Posts: 52
Trades: 0
BETWEEN includes boundaries, what you tell is quite strange.
Marvin Le Rouge is offline
Reply With Quote
View Public Profile
 
Old 05-23-2005, 01:11 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Try this:
PHP Code:
"SELECT * FROM table_name WHERE date>='$from_date' AND date<='$to_date'"
Regards

Ian
__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 05-23-2005, 01:44 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Well if that's the case, all you have to do is push the $from_date back 1 and $to_date forwards one, mktime() should be ablt to do this for you i believe.

That'd be my round about way of doing it anyway.
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 05-23-2005, 03:24 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Using the timestamp function will work, but provided the variables $from_date and $to_date are in the same format as the "date" column in the db table, it would mean unnecessary coding.

It all depends on the set up of the db table.
__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 05-23-2005, 05:49 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Hi everyone.

Sorry, but my email notification didn't seem to work. Let me try all of your solutions and i will get back in a few moments.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 05-23-2005, 06:05 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Ok. Thanks for the help everyone.

The email notification system didn't work and i thought that i had become hugely unpopular here and that no-one wanted to help. But all the contributions guided me towards finding/solving the problem.

The problem:
Upon investigation, i realised that `date` was a datetime. This meant that when i was searching dates without times. This meant that time was taken to be 00:00:00 and that is midnight of the previous night, hence the reason why end_date was not being included (except for transactions that may have taken place at midnight the previous night).

The solution:
By adding the time 23:59:59 (denoting the end of the day) to the end_date, the whole of end_date was included.

LET MY MISTAKES BE A LESSON TO ALL.

Thanks again.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 05-23-2005, 06:12 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Glad to be of assistance Fambi - I'm sure we've all spent many hours on similar omissions in our code/set-up!

__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 05-23-2005, 06:13 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Many hours indeed.

I think we're all in need of a holiday in Spain.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Reply     « Reply to Select... Between
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.72848 seconds with 12 queries