0

i have some PHP code that reads the system time, reads a string from a database field that is a date (but the field isn't a date field), converts that string to date and then runs an if statement comparing the two dates.

however for some reason it doesn't seem to be working properly. I have a simplified version of the code here for testing.

<?php
$currentdate = date("d/m/Y");
$textfield = "25/12/2009";
$my_date = date('d/m/Y', strtotime($textfield));

echo 'Current Date: ',$currentdate,'<br>';
echo 'Selected Date: ',$my_date,'<br>';

if ($currentdate > $my_date) {
    echo "PASS";
} else {
    echo "FAIL";
}
?>

the output i get is

Current Date: 23/04/2015
Selected Date: 01/01/1970
PASS

where have i gone wrong? windows server running PHP Version 5.3.8

chenks
  • 129
  • 1
  • 4
  • 16
  • you should set $textfield = "2009/12/25"; in english format – developer Apr 23 '15 at 08:08
  • i can't set the textfield as that though, as the data in the field i will reading from is in the format "dd/mm/yyyy" – chenks Apr 23 '15 at 08:12
  • OK i think this works, and it appears to give the correct results. could someone confirm? `'; echo 'Selected Date: ',$my_date,'
    '; if ($currentdate > $my_date) { echo "PASS"; } else { echo "FAIL"; } ?>`
    – chenks Apr 23 '15 at 08:23
  • you can use `explode` to reorder date – developer Apr 23 '15 at 08:24

0 Answers0