Solved

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

Posted on 2014-01-10
4
3,129 Views
Last Modified: 2014-01-10
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
0
Comment
Question by:mhdi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 13

Accepted Solution

by:
stergium earned 167 total points
ID: 39770413
try this

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

Open in new window

0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 167 total points
ID: 39770417
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
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 166 total points
ID: 39770420
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
 

Author Comment

by:mhdi
ID: 39770477
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

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question