简体   繁体   中英

How can I get 10 days future date from today in Laravel (PHP)

I'm trying to get a future date from today using PHP.

like date('dS M, Y (D)') returns 21st Jan, 2021 (Thu) (Today)

How can we get a future date from today!

You could use the superb Carbon package by installing it via composer.

Then in your code you can run add days like this

Entering the date piece by piece

$dt = Carbon::create(2021, 1, 22, 0);
echo $dt->addDays(10); // adding 10 days from today on

Using now()

echo Carbon::now()->addDays(10); // adding 10 days from today on

You could use PHP's DateTime class:

    $dt = new DateTime();
    $dt->modify( '+10 days' );
    echo $dt->format( 'dS M, Y (D)' );

https://www.php.net/manual/en/book.datetime.php

You can use it that way. You don't need any package for this job.

$tenDaysLater = date ('Y-m-d', strtotime ('+10 day'));

try this code

$date = date('Y-m-d');
$addDay= strtotime($date . "+10 days"); 

echo date('Y-m-d', $addDay);

You could do this:

$datetime = Carbon::now()->addDays(30);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM