Solved

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

Posted on 2014-01-10
4
3,050 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Dork query 7 66
PHP SMTP authentication 6 28
Convert php array to comma seperated list 19 35
Make an array show the subkey and put it in a query 2 28
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 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