Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc

    Bàn luận If the given dates are in the same format then use a simple comparison operator to compare the dates.

    Example:

    2012-11-24 is latest than 2011-03-26
    
    0

    Cho hai ngày (ngày 1 và ngày 2) và nhiệm vụ là so sánh các ngày đã cho. So sánh hai ngày trong PHP rất đơn giản khi cả hai ngày ở cùng định dạng nhưng vấn đề phát sinh khi cả hai ngày ở một định dạng khác nhau.

    Phương pháp 1: Nếu các ngày đã cho ở cùng định dạng thì sử dụng toán tử so sánh đơn giản để so sánh các ngày.

    2012-11-24 is latest than 2011-03-26
    
    1
    2012-11-24 is latest than 2011-03-26
    
    2
    2012-11-24 is latest than 2011-03-26
    
    3
    2012-11-24 is latest than 2011-03-26
    
    4

    2012-11-24 is latest than 2011-03-26
    
    5
    2012-11-24 is latest than 2011-03-26
    
    22.

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    9

    2012-11-24 is latest than 2011-03-26
    
    9
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    0
    2012-11-24 is latest than 2011-03-26
    
    1
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    2
    2012-11-24 is latest than 2011-03-26
    
    5
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    4

    $date1=date('d/m/y');
    $tempArr=explode('_', '31_12_11');
    $date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2]));
    
    4

    Output:

    1998-11-24 is latest than 1997-03-26
    

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    5
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    6
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    7
    2012-11-24 is latest than 2011-03-26
    
    4
    If both of the given dates are in different formats then use strtotime() function to convert the given dates into the corresponding timestamp format and lastly compare these numerical timestamps to get the desired result.

    Example:

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    5
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    6
    $date1=date('d/m/y');
    $tempArr=explode('_', '31_12_11');
    $date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2]));
    
    2
    2012-11-24 is latest than 2011-03-26
    
    4

    Phương pháp 2: Nếu cả hai ngày đã cho ở các định dạng khác nhau thì hãy sử dụng hàm strtotime () để chuyển đổi các ngày đã cho thành định dạng dấu thời gian tương ứng và cuối cùng so sánh các dấu thời gian số này để có kết quả mong muốn.

    2012-11-24 is latest than 2011-03-26
    
    0

    2012-11-24 is latest than 2011-03-26
    
    1
    2012-11-24 is latest than 2011-03-26
    
    2
    $date1=date('d/m/y');
    $tempArr=explode('_', '31_12_11');
    $date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2]));
    
    8
    2012-11-24 is latest than 2011-03-26
    
    4

    2012-11-24 is latest than 2011-03-26
    
    5
    2012-11-24 is latest than 2011-03-26
    
    2
    $format = "d_m_y";
    $date1  = \DateTime::createFromFormat($format, "03_01_12");
    $date2  = \DateTime::createFromFormat($format, "31_12_11");
    
    var_dump($date1 > $date2);
    
    2224

    $format = "d_m_y";
    $date1  = \DateTime::createFromFormat($format, "03_01_12");
    $date2  = \DateTime::createFromFormat($format, "31_12_11");
    
    var_dump($date1 > $date2);
    
    4
    2012-11-24 is latest than 2011-03-26
    
    2
    $format = "d_m_y";
    $date1  = \DateTime::createFromFormat($format, "03_01_12");
    $date2  = \DateTime::createFromFormat($format, "31_12_11");
    
    var_dump($date1 > $date2);
    
    6
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    0
    2012-11-24 is latest than 2011-03-26
    
    1
    $format = "d_m_y";
    $date1  = \DateTime::createFromFormat($format, "03_01_12");
    $date2  = \DateTime::createFromFormat($format, "31_12_11");
    
    var_dump($date1 > $date2);
    
    9

    2012-11-24 is latest than 2011-03-26
    
    5
    2012-11-24 is latest than 2011-03-26
    
    22.

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    9

    2012-11-24 is latest than 2011-03-26
    
    9
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    0
    2012-11-24 is latest than 2011-03-26
    
    1
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    2
    2012-11-24 is latest than 2011-03-26
    
    5
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    4

    $date1=date('d/m/y');
    $tempArr=explode('_', '31_12_11');
    $date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2]));
    
    4

    Output:

    12-03-26 is latest than 2011-10-24
    

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    5
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    6
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    7
    2012-11-24 is latest than 2011-03-26
    
    4
    Using DateTime class to compare two dates.

    Example:

    2012-11-24 is latest than 2011-03-26
    
    0

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    5
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    6
    $date1=date('d/m/y');
    $tempArr=explode('_', '31_12_11');
    $date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2]));
    
    2
    2012-11-24 is latest than 2011-03-26
    
    4

    Phương pháp 2: Nếu cả hai ngày đã cho ở các định dạng khác nhau thì hãy sử dụng hàm strtotime () để chuyển đổi các ngày đã cho thành định dạng dấu thời gian tương ứng và cuối cùng so sánh các dấu thời gian số này để có kết quả mong muốn.

    2012-11-24 is latest than 2011-03-26
    
    1
    2012-11-24 is latest than 2011-03-26
    
    2
    2012-11-24 is latest than 2011-03-26
    
    3
    2012-11-24 is latest than 2011-03-26
    
    4

    2012-11-24 is latest than 2011-03-26
    
    5
    2012-11-24 is latest than 2011-03-26
    
    22.

    12-03-26 is latest than 2011-10-24
    
    08
    12-03-26 is latest than 2011-10-24
    
    09
    2012-11-24 is latest than 2011-03-26
    
    5
    12-03-26 is latest than 2011-10-24
    
    04
    12-03-26 is latest than 2011-10-24
    
    05
    $format = "d_m_y";
    $date1  = \DateTime::createFromFormat($format, "03_01_12");
    $date2  = \DateTime::createFromFormat($format, "31_12_11");
    
    var_dump($date1 > $date2);
    
    9

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    9

    2012-11-24 is latest than 2011-03-26
    
    9
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    0
    2012-11-24 is latest than 2011-03-26
    
    1
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    2
    2012-11-24 is latest than 2011-03-26
    
    5
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    4

    12-03-26 is latest than 2011-10-24
    
    08
    12-03-26 is latest than 2011-10-24
    
    09
    2012-11-24 is latest than 2011-03-26
    
    5
    12-03-26 is latest than 2011-10-24
    
    04
    12-03-26 is latest than 2011-10-24
    
    05
    $format = "d_m_y";
    $date1  = \DateTime::createFromFormat($format, "03_01_12");
    $date2  = \DateTime::createFromFormat($format, "31_12_11");
    
    var_dump($date1 > $date2);
    
    9

    $date1=date('d/m/y');
    $tempArr=explode('_', '31_12_11');
    $date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2]));
    
    4

    Output:

    2012-11-24 is latest than 2011-03-26
    

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    5
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    6
    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    
    7
    2012-11-24 is latest than 2011-03-26
    
    4


    Cách so sánh hai ngày trong PHP nếu ngày ở định dạng

    12-03-26 is latest than 2011-10-24
    
    29 và
    12-03-26 is latest than 2011-10-24
    
    30.

    Tôi đang sử dụng mã này:

    $date1=date('d_m_y');
    $date2='31_12_11';
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    

    Nhưng nó không hoạt động ..

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Đã hỏi ngày 4 tháng 1 năm 2012 lúc 6:18Jan 4, 2012 at 6:18

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Rohan Kumarrohan KumarRohan Kumar

    Phù bằng vàng 40K1173 Huy hiệu bạc103 Huy hiệu đồng11 gold badges73 silver badges103 bronze badges

    0

    Bạn sẽ phải đảm bảo rằng ngày của bạn là các đối tượng ngày hợp lệ.

    Thử cái này:

    $date1=date('d/m/y');
    $tempArr=explode('_', '31_12_11');
    $date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2]));
    

    Sau đó, bạn có thể thực hiện phương thức

    12-03-26 is latest than 2011-10-24
    
    31 để có được sự khác biệt.

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Đã trả lời ngày 4 tháng 1 năm 2012 lúc 7:17Jan 4, 2012 at 7:17

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    1

    Sử dụng DateTime :: createdFromFormat:

    $format = "d_m_y";
    $date1  = \DateTime::createFromFormat($format, "03_01_12");
    $date2  = \DateTime::createFromFormat($format, "31_12_11");
    
    var_dump($date1 > $date2);
    

    Đã trả lời ngày 4 tháng 1 năm 2012 lúc 7:50Jan 4, 2012 at 7:50

    Nevvermindnevvermindnevvermind

    3.2621 Huy hiệu vàng35 Huy hiệu bạc44 Huy hiệu đồng1 gold badge35 silver badges44 bronze badges

    1

    Không trả lời vấn đề thực tế của OPS, nhưng chỉ trả lời tiêu đề. Vì đây là kết quả hàng đầu cho "so sánh ngày trong PHP".

    Khá đơn giản để sử dụng các đối tượng DateTime (

    12-03-26 is latest than 2011-10-24
    
    32) và so sánh chúng trực tiếp

    $date1 = new DateTime("2009-10-11");
    $date2 = new DateTime("tomorrow"); // Can use date/string just like strtotime.
    var_dump($date1 < $date2);
    

    Đã trả lời ngày 29 tháng 5 năm 2018 lúc 21:01May 29, 2018 at 21:01

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Mohd Abdul Mujibmohd Abdul MujibMohd Abdul Mujib

    12.3k8 Huy hiệu vàng60 Huy hiệu bạc86 Huy hiệu Đồng8 gold badges60 silver badges86 bronze badges

    1

    Hàm date_diff () trả về sự khác biệt giữa hai đối tượng DateTime.

    Nếu ngày đầu tiên là trước ngày thứ hai, số ngày dương sẽ được trả lại; nếu không thì một số ngày âm:

    format("%R%a days");
    ?>
    

    đầu ra sẽ là "+272 ngày";

    Thay đổi $ ngày1 = "2014-03-15"

     format("%R%a days");
        ?>
    

    Đầu ra sẽ là "-93 ngày"

    Đã trả lời ngày 17 tháng 3 năm 2015 lúc 13:03Mar 17, 2015 at 13:03

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    RishabhrishabhRishabh

    4865 Huy hiệu bạc8 Huy hiệu Đồng5 silver badges8 bronze badges

    format("%R%a")>0){
                 echo "active";
           }else{
               echo "inactive";
           }
           echo "Remaining Days ".$diff->format("%R%a days");
    ?>
    

    Đã trả lời ngày 17 tháng 11 năm 2015 lúc 8:09Nov 17, 2015 at 8:09

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    ManikantamanikantaManikanta

    Phù hiệu Bạc 19333 silver badges15 bronze badges

    1

    Mở rộng câu trả lời của @nevermind, người ta có thể sử dụng datetime :: createdfromformat: thích,

    12-03-26 is latest than 2011-10-24
    
    0

    Đã trả lời ngày 20 tháng 5 năm 2015 lúc 8:45May 20, 2015 at 8:45

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Rohan Kumarrohan KumarRohan Kumar

    Phù bằng vàng 40K1173 Huy hiệu bạc103 Huy hiệu đồng11 gold badges73 silver badges103 bronze badges

    Bạn sẽ phải đảm bảo rằng ngày của bạn là các đối tượng ngày hợp lệ.

    12-03-26 is latest than 2011-10-24
    
    1

    Thử cái này:

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Sau đó, bạn có thể thực hiện phương thức

    12-03-26 is latest than 2011-10-24
    
    31 để có được sự khác biệt.Dec 8, 2014 at 12:16

    1

    Đã trả lời ngày 4 tháng 1 năm 2012 lúc 7:17

    12-03-26 is latest than 2011-10-24
    
    2

    Sử dụng DateTime :: createdFromFormat:Jun 21, 2017 at 19:07

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Đã trả lời ngày 4 tháng 1 năm 2012 lúc 7:50

    Nevvermindnevvermind

    12-03-26 is latest than 2011-10-24
    
    3

    3.2621 Huy hiệu vàng35 Huy hiệu bạc44 Huy hiệu đồngJan 12, 2021 at 1:41

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Không trả lời vấn đề thực tế của OPS, nhưng chỉ trả lời tiêu đề. Vì đây là kết quả hàng đầu cho "so sánh ngày trong PHP".

    Khá đơn giản để sử dụng các đối tượng DateTime (

    12-03-26 is latest than 2011-10-24
    
    32) và so sánh chúng trực tiếp

    Đã trả lời ngày 29 tháng 5 năm 2018 lúc 21:0123 gold badges127 silver badges187 bronze badges

    Mohd Abdul Mujibmohd Abdul MujibJan 4, 2012 at 6:25

    12.3k8 Huy hiệu vàng60 Huy hiệu bạc86 Huy hiệu Đồngianace

    Hàm date_diff () trả về sự khác biệt giữa hai đối tượng DateTime.2 gold badges17 silver badges31 bronze badges

    Nếu ngày đầu tiên là trước ngày thứ hai, số ngày dương sẽ được trả lại; nếu không thì một số ngày âm:

    12-03-26 is latest than 2011-10-24
    
    4

    đầu ra sẽ là "+272 ngày";Mar 4, 2015 at 9:31

    Thay đổi $ ngày1 = "2014-03-15"Alun

    Đầu ra sẽ là "-93 ngày"2 bronze badges

    Đã trả lời ngày 17 tháng 3 năm 2015 lúc 13:03

    Eg.:

    12-03-26 is latest than 2011-10-24
    
    5

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Rishabhrishabh

    4865 Huy hiệu bạc8 Huy hiệu Đồng21 gold badges75 silver badges127 bronze badges

    Đã trả lời ngày 17 tháng 11 năm 2015 lúc 8:09Mar 20, 2017 at 13:49

    Manikantamanikanta

    12-03-26 is latest than 2011-10-24
    
    6

    Phù hiệu Bạc 1933

    Mở rộng câu trả lời của @nevermind, người ta có thể sử dụng datetime :: createdfromformat: thích,5 gold badges40 silver badges57 bronze badges

    Đã trả lời ngày 20 tháng 5 năm 2015 lúc 8:45Jan 4, 2012 at 6:30

    Bạn có thể thử một cái gì đó như:devdRew

    Sau đó, bạn có thể truy cập sự khác biệt trong những ngày như $ datediff-> d này;3 gold badges22 silver badges33 bronze badges

    Đã trả lời ngày 8 tháng 12 năm 2014 lúc 12:16

    Thử cái này

    Đã trả lời ngày 21 tháng 6 năm 2017 lúc 19:07Dec 4, 2018 at 10:51

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    So sánh điểm chuẩn Date_Create, Strtotime, DateTime và Direct

    12-03-26 is latest than 2011-10-24
    
    8

    Tôi chỉ đã thêm hai dòng nữa với mã của bạn

    Đã trả lời ngày 20 tháng 12 năm 2018 lúc 7:11Dec 20, 2018 at 7:11

    SantisantiSanti

    6288 Huy hiệu bạc22 Huy hiệu Đồng8 silver badges22 bronze badges

    Nếu cả hai ngày ở cùng định dạng thì hãy sử dụng toán tử so sánh.

    12-03-26 is latest than 2011-10-24
    
    9

    Đầu ra: 2018-05-05 cũ hơn 2019-08-19

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    Bhargav Rao

    47.4K27 Huy hiệu vàng122 Huy hiệu bạc137 Huy hiệu đồng27 gold badges122 silver badges137 bronze badges

    Đã trả lời ngày 20 tháng 8 năm 2019 lúc 5:31Aug 20, 2019 at 5:31

    Hướng dẫn how can i compare two dates in php? - làm thế nào tôi có thể so sánh hai ngày trong php?

    1

    Làm thế nào tôi có thể so sánh ngày hôm nay với một ngày khác trong PHP?

    Khi bạn đã tạo các đối tượng DateTime của mình, bạn cũng có thể gọi phương thức diff () trên một đối tượng và chuyển nó vào ngày khác để tính toán chênh lệch giữa các ngày. Điều này sẽ cung cấp cho bạn một đối tượng DateInterval. $ last = new DateTime ("25 tháng 12 năm 2020");call the diff() method on one object and pass it the other date in order to calculate the difference between the dates. This will give you back a DateInterval object. $last = new DateTime( "25 Dec 2020" );

    Làm thế nào tôi có thể kiểm tra xem một ngày có lớn hơn hôm nay trong PHP không?

    Kiểm tra PHP nếu ngày lớn hơn so với ngày hôm nay..
    $ date_now = new DateTime () ;.
    $ date2 = new DateTime ("01/02/2016") ;.
    if ($ date_now> $ date2) {.
    echo 'lớn hơn' ;.
    }else{.
    Echo 'ít hơn' ;.

    Làm thế nào có thể kiểm tra nếu điều kiện tính theo ngày trong PHP?

    Làm thế nào để so sánh hai ngày trong điều kiện trong câu trả lời mã PHP..
    $ hôm nay = ngày ("y-m-d") ;.
    $ hết hạn = $ hàng-> hết hạn;// từ cơ sở dữ liệu ..
    $ TODAY_TIME = Strtotime ($ ngay hôm nay) ;.
    $ expire_time = strtotime ($ expire) ;.
    if ($ expire_time <$ Today_time) { / * làm điều gì đó * /}.

    Làm thế nào ngày kiểm tra có thể ít hơn ngày hiện tại trong PHP?

    PHP $ date1 = "2010-01-15";$ date2 = "2020-12-14";$ Timestamp1 = Strtotime ($ date1);$ Timestamp2 = Strtotime ($ date2);if ($ Timestamp1> $ Timestamp2) echo "$ date1 lớn hơn $ ngày2";other echo "$ date1 là ít hơn $ date2";?> PHP là gì và tôi có thể học nó như thế nào?Làm thế nào để lặp lại một mảng trong PHP?if ($timestamp1 > $timestamp2) echo "$date1 is greater than $date2"; else echo "$date1 is less than $date2"; ?> What is PHP and how can I learn it? How to echo an array in PHP?