簡體   English   中英

PHP 日期大於今天的日期不起作用

[英]PHP date greater than todays date not working

我已經看遍了,我無法弄清楚為什么這不起作用。 我正在嘗試將今天的日期與我設置的日期進行比較。 我想知道日期是否大於或等於今天的日期。 由於某種原因,我的代碼不起作用,我不知道為什么。 這是我的代碼:

    <?php 
 $date_now = date("d-m-Y");      
             
if (($date_now >= date("01-12-2020"))) { ?>

            greater than 1st

   <?php  } else { ?>

            not greater than

   <?php  } ?>

我相信這很簡單,但我已經看遍了,我無法弄清楚我錯過了什么。

您可以嘗試使用\\strtotime()原生 php 函數

<?php
$date_now = date("d-m-Y");

// now compare date as timestamp
// 1606780800 (1st december 2020) is greater than 1606176000 (24th november 2020)
if (\strtotime($date_now) >= \strtotime(date("01-12-2020"))) {

    echo 'greater than 1st';

 }  else {

    echo 'not greater than';
  }

\\strtotime使您能夠從日期中檢索時間戳(作為文本或區域設置符號)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM