0

I have date with this format

format('Y-m-d H:i:s');

How can i do this

$hola == $hi + 10000;

Like i add to the current time 10000 seconds ?

$dt = new DateTime();
$hi = $dt->format('Y-m-d H:i:s');
$hola == $hi + 10000;
echo $hola;

This script gives me a blank page ,

Gabataba
  • 3
  • 2

3 Answers3

2

You just have to use DateTime::add() before formatting it as a string

$date = new DateTime();
$date->add(new DateInterval('PT10000S')); // adds 10000 secs
echo $date->format('Y-m-d H:i:s');

Also, on the line $hola == $hi + 10000; you use a comparison operator. this will throw an error. If you have not set display_errors to 1 in your php config, the error will be silenced and a blank page will be returned

ᴄʀᴏᴢᴇᴛ
  • 2,939
  • 26
  • 44
1

You can use .modify() on the DateTime object.

$dt = new DateTime();
$dt->modify('+10000 seconds');
echo $dt->format('Y-m-d H:i:s');
Jim Wright
  • 5,905
  • 1
  • 15
  • 34
1

According to your code you are using comparison operator == so its comparing $hola blank variable with $hi+10000 which is not correct.

If you are trying to add date with number you can do this:

$Date1 = '2010-09-17';
$date = new DateTime($Date1);
$date->add(new DateInterval('P1D')); // P1D means a period of 1 day
$Date2 = $date->format('Y-m-d');

For more info: Click here

Manav
  • 553
  • 7
  • 18