The BETWEEN funtion

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

The BETWEEN funtion

Post by JayBird »

I have this query which add up the ammout spent in petty cash between two dates

Code: Select all

// Date the petty cash system started
$startOfCashDate = "2003-10-01";

// The date of the end of last month
$endoflastmonth = $last_year."-".$last_month."-".$lastday."";

$sql = "SELECT SUM(debit_amount) FROM petty_cash WHERE date_spent BETWEEN '$startOfCashDate' AND '$endoflastmonth'";
From what i can see, BETWEEN returns all the figures between the two dates not including the to date.

How can i get bwetween and including?

Thanks

Mark
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

link says that it depends on your database...
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

WHERE date_spent >= '$startOfCashDate'
AND date_spent <= '$endoflastmonth'";
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Ahh! nice one fractalvibes! I didn't even think about that!!
Post Reply