SQL Date

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

SQL Date

Post by glennalmeda »

What is the SQL Statement for searching a record in between two dates? Thank You!
jaxn
Forum Commoner
Posts: 55
Joined: Fri Jan 16, 2004 1:50 pm
Location: Nashville, TN

Post by jaxn »

I could be wrong on this, but I think the only SQL99 way to do it is with BETWEEN.

i.e.

Code: Select all

SELECT date FROM table WHERE date BETWEEN '$start_date' AND '$end_date'
$start_date and $end_date need to be in the proper format for your date column (YYYYMMDD for date type columns).

Most databases have special functions for working with dates. Here is a list of the ones for MySQL.
http://www.mysql.com/doc/en/Date_and_ti ... tions.html

-Jackson
Post Reply