Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Giả sử tôi có một ngày ở định dạng sau: 2010-12-11 (năm tháng)

Với PHP, tôi muốn tăng ngày một tháng và tôi muốn năm được tự động tăng lên, nếu cần thiết (nghĩa là tăng từ tháng 12 năm 2012 đến tháng 1 năm 2013).

Regards.

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Đã hỏi ngày 20 tháng 5 năm 2010 lúc 0:15May 20, 2010 at 0:15

1

$time = strtotime("2010.12.11");
$final = date("Y-m-d", strtotime("+1 month", $time));

// Finally you will have the date you're looking for.

Joeri

2.03921 Huy hiệu bạc22 Huy hiệu đồng21 silver badges22 bronze badges

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

Raphael Caixetaraphael CaixetaRaphael Caixeta

7.7709 Huy hiệu vàng50 Huy hiệu bạc76 Huy hiệu Đồng9 gold badges50 silver badges76 bronze badges

6

Tôi cần chức năng tương tự, ngoại trừ chu kỳ hàng tháng (cộng với tháng, trừ 1 ngày). Sau khi tìm kiếm S.O. Trong một thời gian, tôi đã có thể tạo ra giải pháp plug-n-play này:

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }

Thí dụ:

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Alfie

2.3092 huy hiệu vàng27 Huy hiệu bạc44 Huy hiệu đồng2 gold badges27 silver badges44 bronze badges

Đã trả lời ngày 3 tháng 6 năm 2014 lúc 11:55Jun 3, 2014 at 11:55

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

JasonjasonJason

8349 Huy hiệu bạc14 Huy hiệu đồng9 silver badges14 bronze badges

7

Sử dụng

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
9.

$start = new DateTime("2010-12-11", new DateTimeZone("UTC"));
$month_later = clone $start;
$month_later->add(new DateInterval("P1M"));

Tôi đã sử dụng bản sao vì thêm sửa đổi đối tượng gốc, có thể không mong muốn.

Đã trả lời ngày 20 tháng 5 năm 2010 lúc 0:17May 20, 2010 at 0:17

Matthew Flaschenmatthew FlaschenMatthew Flaschen

Phù bằng vàng 273K50511 Huy hiệu bạc537 Huy hiệu đồng50 gold badges511 silver badges537 bronze badges

1

strtotime( "+1 month", strtotime( $time ) );

Điều này trả về một dấu thời gian có thể được sử dụng với hàm ngày

Đã trả lời ngày 20 tháng 5 năm 2010 lúc 0:18May 20, 2010 at 0:18

GalengalenGalen

29,9k9 Huy hiệu vàng71 Huy hiệu bạc89 Huy hiệu Đồng9 gold badges71 silver badges89 bronze badges

4

Bạn có thể sử dụng

$start = new DateTime("2010-12-11", new DateTimeZone("UTC"));
$month_later = clone $start;
$month_later->add(new DateInterval("P1M"));
0 như thế này:

$date = new DateTime('2010-12-11');
$date->modify('+1 month');

Xem tài liệu:

https://php.net/manual/en/datetime.modify.php

https://php.net/manual/en/class.datetime.php


Cập nhật tháng 1 năm 2021: Những sai lầm chính xác được nêu ra bởi các bình luận

Giải pháp này có một số vấn đề trong nhiều tháng với 31 ngày như tháng 5, v.v.

Ví dụ: Điều này nhảy từ ngày 31 tháng 5 đến ngày 1 tháng 7 không chính xác.

Để sửa điều đó, bạn có thể tạo chức năng tùy chỉnh này

function addMonths($date,$months){
    
    $init=clone $date;
    $modifier=$months.' months';
    $back_modifier =-$months.' months';
   
    $date->modify($modifier);
    $back_to_init= clone $date;
    $back_to_init->modify($back_modifier);
   
    while($init->format('m')!=$back_to_init->format('m')){
        $date->modify('-1 day')    ;
        $back_to_init= clone $date;
        $back_to_init->modify($back_modifier);   
    }
}

Sau đó, bạn có thể sử dụng nó như thế:

$date = new DateTime('2010-05-31');
addMonths($date, 1);
print_r($date);
//DateTime Object ( [date] => 2010-06-30 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Berlin ) 

Giải pháp này đã được tìm thấy trong php.net được đăng bởi jenspj: https://www.php.net/manual/fr/datetime.modify.php#107592

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Syscall

18.4K10 Huy hiệu vàng34 Huy hiệu bạc 50 Huy hiệu Đồng10 gold badges34 silver badges50 bronze badges

Đã trả lời ngày 1 tháng 11 năm 2017 lúc 11:49Nov 1, 2017 at 11:49

HrouxhrouxHRoux

36310 Huy hiệu bạc13 Huy hiệu đồng10 silver badges13 bronze badges

3

(date('d') > 28) ? date("mdY", strtotime("last day of next month")) : date("mdY", strtotime("+1 month"));

Điều này sẽ bù đắp cho tháng hai và các tháng khác 31 ngày. Tất nhiên bạn có thể kiểm tra nhiều hơn để có được chính xác hơn cho các định dạng ngày tương đối 'trong ngày hôm nay' (không hoạt động đáng buồn, xem bên dưới) và bạn cũng có thể sử dụng DateTime.

Cả

$start = new DateTime("2010-12-11", new DateTimeZone("UTC"));
$month_later = clone $start;
$month_later->add(new DateInterval("P1M"));
1 và
$start = new DateTime("2010-12-11", new DateTimeZone("UTC"));
$month_later = clone $start;
$month_later->add(new DateInterval("P1M"));
2 về cơ bản là thêm 31 ngày bất kể số ngày trong tháng tiếp theo.

  • 2010-01-31 => Ngày 3 tháng 3
  • 2012-01-31 => Ngày 2 tháng 3 (Năm Leap)

Đã trả lời ngày 10 tháng 11 năm 2014 lúc 22:07Nov 10, 2014 at 22:07

Wayne Weibelwayne WeibelWayne Weibel

9131 Huy hiệu vàng14 Huy hiệu bạc22 Huy hiệu đồng1 gold badge14 silver badges22 bronze badges

1

Vui lòng đầu tiên bạn đặt định dạng ngày của mình như 12-12-2012

Sau khi sử dụng chức năng này, nó hoạt động đúng;

$date =  date('d-m-Y',strtotime("12-12-2012 +2 Months");

Tại đây 12-12-2012 là ngày của bạn và +2 tháng tăng của tháng;

Bạn cũng tăng dần của năm, ngày

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
0

ANS là 12-12-2013

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Pang

9.264146 Huy hiệu vàng85 Huy hiệu bạc120 Huy hiệu đồng146 gold badges85 silver badges120 bronze badges

Đã trả lời ngày 15 tháng 11 năm 2016 lúc 9:32Nov 15, 2016 at 9:32

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Pravin Sutharpravin SutharPravin Suthar

1.3651 Huy hiệu vàng13 Huy hiệu bạc25 Huy hiệu đồng1 gold badge13 silver badges25 bronze badges

Tôi sử dụng theo cách này:-

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
1

Đã trả lời ngày 19 tháng 1 năm 2015 lúc 5:42Jan 19, 2015 at 5:42

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Vineetvineetvineet

13.4K10 Huy hiệu vàng53 Huy hiệu bạc76 Huy hiệu đồng10 gold badges53 silver badges76 bronze badges

3

Chỉ cần cập nhật câu trả lời bằng phương pháp đơn giản để tìm ngày sau không có tháng. Vì câu trả lời tốt nhất được đánh dấu không đưa ra giải pháp chính xác.

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
2

Đã trả lời ngày 22 tháng 11 năm 2019 lúc 12:52Nov 22, 2019 at 12:52

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

AshokashokAshok

75211 Huy hiệu bạc20 Huy hiệu Đồng11 silver badges20 bronze badges

2

Nếu bạn muốn nhận ngày một tháng kể từ bây giờ, bạn có thể làm điều đó như thế này

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
3

Nếu bạn muốn có được ngày hai tháng kể từ bây giờ, bạn có thể đạt được điều đó bằng cách làm điều này

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
4

Và như vậy, đó là tất cả.

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Dharman ♦

28.6K21 Huy hiệu vàng79 Huy hiệu bạc129 Huy hiệu đồng21 gold badges79 silver badges129 bronze badges

Đã trả lời ngày 6 tháng 9 năm 2020 lúc 4:34Sep 6, 2020 at 4:34

1

Cảm ơn Jason, bài viết của bạn rất hữu ích. Tôi đã định dạng lại nó và thêm nhiều ý kiến ​​để giúp tôi hiểu tất cả. Trong trường hợp giúp đỡ bất cứ ai, tôi đã đăng nó ở đây:

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
5

Đã trả lời ngày 13 tháng 11 năm 2016 lúc 20:14Nov 13, 2016 at 20:14

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

GreggreGreg

6211 Huy hiệu vàng8 Huy hiệu bạc15 Huy hiệu đồng1 gold badge8 silver badges15 bronze badges

1

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
6

Nếu bạn muốn tăng theo nhiều ngày, bạn cũng có thể làm điều đó

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
7

Đã trả lời ngày 6 tháng 5 năm 2017 lúc 8:13May 6, 2017 at 8:13

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

1

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
8

Ví dụ sử dụng:

function add_months($months, DateTime $dateObject) 
    {
        $next = new DateTime($dateObject->format('Y-m-d'));
        $next->modify('last day of +'.$months.' month');

        if($dateObject->format('d') > $next->format('d')) {
            return $dateObject->diff($next);
        } else {
            return new DateInterval('P'.$months.'M');
        }
    }

function endCycle($d1, $months)
    {
        $date = new DateTime($d1);

        // call second function to add the months
        $newDate = $date->add(add_months($months, $date));

        // goes back 1 day from date, remove if you want same day of month
        $newDate->sub(new DateInterval('P1D')); 

        //formats final date to Y-m-d form
        $dateReturned = $newDate->format('Y-m-d'); 

        return $dateReturned;
    }
9

Đã trả lời ngày 22 tháng 12 năm 2016 lúc 10:28Dec 22, 2016 at 10:28

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

T30T30T30

10,8K6 Huy hiệu vàng52 Huy hiệu bạc57 Huy hiệu Đồng6 gold badges52 silver badges57 bronze badges

Đối với bất cứ ai tìm kiếm một câu trả lời cho bất kỳ định dạng ngày nào.

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
0

Chỉ cần thay đổi định dạng ngày.

Đã trả lời ngày 1 tháng 6 năm 2017 lúc 17:17Jun 1, 2017 at 17:17

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

FabriciofabricioFabricio

2421 Huy hiệu bạc8 Huy hiệu đồng1 silver badge8 bronze badges

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
1

Đã trả lời ngày 30 tháng 9 năm 2020 lúc 4:56Sep 30, 2020 at 4:56

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

1

Tôi thấy hàm mtkime () hoạt động rất tốt cho việc này:

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
2

Kết quả: 2021-11-01

Tôi thích trừ 1 từ 'ngày' để sản xuất '2021-10-31' có thể hữu ích nếu bạn muốn hiển thị một phạm vi trong 12 tháng, ví dụ: Ngày 1 tháng 10 năm 2021 đến ngày 30 tháng 9 năm 2022

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
3

Kết quả: 2022-09-30

Đã trả lời ngày 11 tháng 1 lúc 13:35Jan 11 at 13:35

Nó hoạt động với tất cả các ngày. Ví dụ, 2013-05-31 sẽ hiển thị 30 tháng Sáu.

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
4

Đã trả lời ngày 25 tháng 6 lúc 13:07Jun 25 at 13:07

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Đặt một hộp vào hộp đầu vào sau đó nhấp vào nút Nhận ngày kể từ ngày trong JQuery

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
5

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Hamza Zafeer

2.27013 Huy hiệu vàng33 Huy hiệu bạc41 Huy hiệu đồng13 gold badges33 silver badges41 bronze badges

Đã trả lời ngày 23 tháng 2 năm 2018 lúc 11:13Feb 23, 2018 at 11:13

0

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
6

Đã trả lời ngày 10 tháng 8 năm 2018 lúc 6:26Aug 10, 2018 at 6:26

1

Tất cả các giải pháp được trình bày không hoạt động đúng. Strtotime () và DateTime :: Thêm hoặc DateTime :: Sửa đổi cho kết quả không hợp lệ đôi khi. Ví dụ: - 31.08.2019 + 1 tháng cho 01.10.2019 thay vì 30.09.2019 - 29.02.2020 + 1 năm cho 01.03.2021 thay vì 28.02.2021 (được thử nghiệm trên Php 5.5, Php 7.3)are not working properly.
strtotime() and DateTime::add or DateTime::modify give sometime invalid results.
Examples:
- 31.08.2019 + 1 month gives 01.10.2019 instead 30.09.2019
- 29.02.2020 + 1 year gives 01.03.2021 instead 28.02.2021
(tested on PHP 5.5, PHP 7.3)

Dưới đây là chức năng của tôi dựa trên ý tưởng được đăng bởi Angelo giải quyết vấn đề:

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
7

Ví dụ sử dụng:

$startDate = '2014-06-03'; // select date in Y-m-d format
$nMonths = 1; // choose how many months you want to move ahead
$final = endCycle($startDate, $nMonths); // output: 2014-07-02
8

Đã trả lời ngày 27 tháng 5 năm 2019 lúc 15:59May 27, 2019 at 15:59

Hướng dẫn how to add 1 month to a date php? - cách thêm 1 tháng vào ngày php?

Làm thế nào tôi có thể nhận được ngày đầu tiên và ngày của tháng trước trong PHP?

Php echo 'ngày đầu tiên =' .date ('y-m-01'). '';echo 'ngày cuối cùng =' .date ('y-m-t').echo 'First Date = ' . date('Y-m-01') . '
'; echo 'Last Date = ' .
date('Y-m-t') .

Bây giờ () trả về trong PHP là gì?

Hàm bây giờ () trả về ngày và thời gian hiện tại.Lưu ý: Ngày và thời gian được trả về dưới dạng "Yyyy-MM-DD HH-MM-SS" (chuỗi) hoặc dưới dạng YYYyMMDDHHMMSS.uuuuuu (số).the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS. uuuuuu (numeric).

Hàm date_sub () trừ đi một số ngày, tháng, năm, giờ, phút và giây kể từ một ngày.

Làm cách nào để thay đổi định dạng ngày trong PHP?.

Chúng ta có thể đạt được chuyển đổi này bằng cách sử dụng hàm strtotime () và date ().Đây là các chức năng tích hợp của PHP ..

Chúng ta có thể đạt được chuyển đổi này bằng cách sử dụng hàm strtotime () và date ().Đây là các chức năng tích hợp của PHP ...
$ orgdate = "2019-09-15" ;.
$ newDate = date ("d-m-y", strtotime ($ orgdate)) ;.
Echo "Định dạng ngày mới là:".$ newdate."(Mm-dd-yyyy)" ;.
Tôi có thể trừ ngày trong PHP không?