Solved

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

Posted on 2014-01-10
4
2,875 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
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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now