PHP - Check if string of date/time is less than 24 hours ago.

Hi,

How do I check if $input is less than 24 hours ago? I cant seem to get the conversions right.
$input = "10/01/2014 07:28:32";

Open in new window


I tried this but it didnt work -
if(strtotime($input) < (time() - (3600*24)))

Open in new window


Thank you
mhdiAsked:
Who is Participating?
 
stergiumConnect With a Mentor Commented:
try this

$date = '10/01/2014 07:28:32';
if (strtotime("$date +1 day") <= time()) {
    // Do something
}

Open in new window

0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
You should read this page http://us3.php.net/manual/en/function.strtotime.php and the page about Date and Time Formats which will tell you what is acceptable.  Using slashes can be a problem too as is mentioned on that page.
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
if the error/issue is that the strtotime does not properly recognize the date/time, you need to use another function:
http://be2.php.net/manual/en/function.date-parse-from-format.php
0
 
mhdiAuthor Commented:
Thanks for the comments. Those links where very helpful.

@stergium I was very confused for a long time, but it seems your code works if I reverse the <= it should be >=
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.