This problem has me stumped I'm trying to select entries in the MYSQL database between two dates.
Database tables
ID - date -------- strtotime ---- cost
01 - 01-01-2010 - 1262300400 - 10
I'm working out the 'strtotime' using the snippit below. I fill the 'strtotime' table with the output, is this giving me the correct timestrings?
<?php
$seconds_in_day = (60*60*24);
$timestring = (strtotime('01-01-2010'));
for ($i = 1; $i <= 365; $i++) {
//echo 'Day ' . $i . ' = ';
//echo date('d-m-Y', $timestring).' ';
echo ($timestring . '<br />');
$timestring = ($timestring + $seconds_in_day) ;
}
?>
I have a form for filling the 'Cost' table between selected dates, E.G between 01-01-2010 to 01-04-2010
The form send the dates in 'dd-mm-yyyy' format.
I convert to strtotime using:
<?php
$formdate_start = ($_POST['start_date'])
$formdate_end = ($_POST['end_date'])
$date_string_start = (strtotime($formdate_start));
$date_string_end = (strtotime($formdate_end));
?>
I select the ID's of the two dates and use these in my sql_update
<?php
$query_Update_prices = "SELECT id FROM `database_name` WHERE date_strtotime BETWEEN $formdate_start AND $formdate_end";
?>
Everthing looks OK until I select dates pairs which include 29-03-2010
$formdate_start = 01-01-2010, $formdate_end = 28-03-2010, selects 1-87 the correct number
$formdate_start = 01-01-2010, $formdate_end = 29-03-2010, selects 1-87 the incorrect number it should be 1-88
$formdate_start = 01-01-2010, $formdate_end = 30-03-2010, selects 1-88 the incorrect number it should be 1-89
Selecting date pairs which don't include 29-03-2010 work fine.
Where am I going wrong? Any help would be much appreciated.