Date Between And

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glennalmeda
Forum Newbie
Posts: 14
Joined: Mon Jan 26, 2004 9:00 pm

Date Between And

Post by glennalmeda »

Code: Select all

$sqlQty = "SELECT * FROM sales_invoice WHERE company = '$company' AND date BETWEEN '$frmDate' AND '$ThruDate' AND payment_status = 'Paid'";

this is my code to get fields between two dates..
but i cant get the data if i input two same dates.
for example:


Code: Select all

$frmDate = 2004-02-12
$ThruDate = 2004-02-12
because i want to get the data for the current date...
let say today is feb 12, i can only get the data for that day if the date i input are 2004-02-12 to 2004-02-13.

what should be my sql statement...? thanks
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

You might be able to add the time to those date strings.

Like:

$fromdate = "2004-02-12 00:00:00";
$todate = "2004-02-12 11:59:59";
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

select * from test where date between '2004-03-03' and '2004-03-04'
Worked for me using DATE fieldtypes. I got two hits. If I change the DATE to DATETIME, and added a second to the later (2004-03-04 00:00:01), then it failed (only one hit).

If you are not using DATE as fieldtypes, you likely have this issue. You should however be able to use cast/convert to bypass it.
Post Reply