My date is being returned like 01/05/2013 12:44
. How do I check in php if this datetime is in the future?
Asked
Active
Viewed 486 times
0

Claire
- 3,683
- 13
- 47
- 74
-
Where do you get this data ? From the user ? – gkalpak May 28 '13 at 09:07
-
I cannot format it in a different way – Claire May 28 '13 at 09:08
-
Convert to both date to timestamp and compare – Pramod Kumar Sharma May 28 '13 at 09:08
-
@Nicola: It didn't ask to format it. I aksed where do you get it from. E.g. if it comes from the client side, you need to apply timezone changes, beacause the client and server might be on different timezones. – gkalpak May 28 '13 at 09:10
-
ah I see, sorry about that. No it comes from the server. – Claire May 28 '13 at 09:11
-
Did you search for your question? This has been answered on more than one occasion, like [here](http://stackoverflow.com/questions/2832467/php-how-can-i-check-if-the-current-date-time-is-past-a-set-date-time) for example. – George May 28 '13 at 09:13
4 Answers
1
Try this:
<?php
$dt = '01/05/2013 12:44';
$nowdt = time();
$diff = strtotime($dt) - $nowdt;
echo $diff;
if($diff > 0){
echo (" your date is future date");
} else {
echo ("your date is is not future date");
}
?>

Vijaya Pandey
- 4,252
- 5
- 32
- 57
0
You can compare time() with the UNIX timestamp representation of that date:
if (time() < strtotime("01/05/2013 12:44"))
{
// your time is greater than todays date
}
Another way
$time = strtotime(str_replace("/","-",$date) )
if ($time > time())
{
echo "$date is in the future."
}

Yogus
- 2,307
- 5
- 20
- 38
-
-
I am trying to convert my datetime format to something like 30th May 2013 8pm, but when I do an echo of `strtotime($meetings[0]['date'])` nothing prints out. Why is this? I did try to format it but it was coming out with 1-1-1970 so thats why I echoed the value. I have also tried print_r. – Claire May 28 '13 at 09:50
-
Its not working after all :(. I just changed my date to the past and it was still showing it. – Claire May 28 '13 at 09:53
-
0
Convert to Unix time, then see if it's greater than the current time.
<?php
if(strtotime("01/05/2013 12:44") > time()) {
//time is in the future.
}else{
//time is in the past
}
?>

ajdi
- 444
- 1
- 4
- 13