Jump to content

How to find records between two dates in mysql


t_machine

Recommended Posts

hi, I am wondering if anyone could help with this problem I have.
I have a large list of records, each with the date they were stored in the database. How can I display only the records entered within a certain data period.

Example
$sql = "SELECT * FROM _table where date_added is between 07,Dec,2006 and 23,Jan,2007

I stored the date as time stamped time()..
I think I would have to format the date_added column like this -> DATE_FORMAT(FROM_UNIXTIME(date_added), '%d,%m,%Y') but how do I check if it's between the above time period.

Thanks :)
if the dates in the database are timestamps then just change the dates you are searching between into timestamps too and then use the variable sin your query
[code]
<?php
$start = strtotime("07 December 2006");
$end  = strtotime("23 January 2007");
$sql = "SELECT * FROM _table WHERE date_added BETWEEN '$start' AND '$end'";
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.