2013-09-26 13 views

cevap

40

Sen PHP'nin DateTime sınıfla tarihleri ​​karşılaştırabilirsiniz:

$date = new DateTime($event['date']); 
$now = new DateTime(); 

if($date < $now) { 
    echo 'date is in the past'; 
} 
Not

See it live!


: DateTime sınıfını kullanarak sadece 2038 okuyun önceki tarihler için çalışacak ikincisi beri strtotime() fazla tercih edilir Year_2038_problem hakkında daha fazla bilgi.

1
if (time() > strtotime($event['date'])) 
{ 
    // current date is greater than 2013-07-31 
} 

strtotimethese rules kullanarak tarih acı ayrıştırır. Bir sağ çözümü (@Amal Murali)

Burada girişi çıkışı, bugün tarihi bakınız olarak yanlış cevap kabul ettik ama geçmiş tarihi olarak geçerli tarih döndüren Satch3000 @

-1

.

<?php 

/* Enter today date */ 
$date = new DateTime("09/14/2017"); 
$now = new DateTime(); 

print_r($date); 

print_r($now); 


if($date < $now) { 
    echo 'date is in the past'; 
} 

Çıktı olacaktır

DateTime Object 
(
    [date] => 2017-09-14 00:00:00.000000 
    [timezone_type] => 3 
    [timezone] => UTC 
) 
DateTime Object 
(
    [date] => 2017-09-14 07:12:52.000000 
    [timezone_type] => 3 
    [timezone] => UTC 
) 
date is in the past 

Çözüm

$Date1 = strtotime(date('Y-m-d', strtotime('2017-09-15'))).' '; 
$Date2 = strtotime(date('Y-m-d')); 

    if($Date1 < $Date2) { 
     echo 'date is in the past'; 
    } 
İlgili konular