Add +1d to current php date

Asked

Viewed 3,251 times

1

I have the following date:

$data = date("Y-d-m H:i:s");

I need to create the following date:

$data_expira = date("Y-d-m H:i:s"); // adicionando +24h 

How can I add +1d on current date?

1 answer

1


ideone result

Starting with PHP 5.2.0, there is a simple way to work with dates and times, with the class DateTime - returns a new Datetime object

$date = new DateTime('+1 day');
echo $date->format('Y-m-d H:i:s');

Another way: ideone result

 $amanha = date("Y-d-m H:i:s", time() + 86400);
 echo $amanha;

Another way: ideone result

$amanha = date('Y-m-d H:i:s', strtotime('+1 days'));
echo $amanha;

For local time use date_default_timezone_set - sets the default time zone used by all date and time functions in a script

Ideone example with date_default_timezone_set ("America/Sao_Paulo");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.