TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-22-2007, 09:36 AM   #1 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default selecting a date range

hi all i have a problem querying date

$from='2007-11-14';
$to='2007-11-16';
$query="select * from table where field_date between '$from' and '$to'";


it displays range from 2007-11-14 to 2007-11-15.?why is 2007-11-16 is not included?? how would i query then if i want to include 2006-11-16 without changing the value of my variables.
meshi is offline  
Reply With Quote
Old 11-22-2007, 01:13 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

2007-11-16 should be included in your BETWEEN clause. Perhaps that is not where the problem lies?

Try the following, which should behave exactly the same as BETWEEN:

sql Code:
SELECT
    *
FROM
    myTable
WHERE
    myDateColumn >= '1982-10-10'
AND
    myDateColumn <= '1985-10-10'
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-22-2007, 01:25 PM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
Salathe is on a distinguished road
Default

What is the column type for field_date? It's only a hypothesis but perhaps the dates are being calculated as BETWEEN 2007-11-14 00:00:00 AND 2007-11-16 00:00:00 which would explain why any rows belonging to the 16th wouldn't be caught.
Salathe is offline  
Reply With Quote
Old 11-29-2007, 01:30 PM   #4 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

yeah.. ur right salathe..the type is timestamp so it would not display the greater than 2007-11-16 00:00:00. its working now...thanks guys
meshi is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:52 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design