-1

I need to retrieve the expire datetime starting from the current datetime + some time.

The example is:

$current_datetime = date('Y-m-d H:m:s');
$expire_time = 24;// 1 day in hours as int() for example ;)

$expire_datetime = date($current_datetime + $expire_time); //don't know how to do this in Y-m-d H:m:s format!!

I would like to write down an helper lib starting from this script.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
itsme
  • 48,972
  • 96
  • 224
  • 345
  • http://php.net/manual/en/datetime.add.php http://stackoverflow.com/questions/985818/php-date-time-current-time-add-minutes http://stackoverflow.com/questions/2242601/add-days-and-hours-in-date-time-field-and-get-the-updated-date-time-in-php-using http://stackoverflow.com/questions/7811609/php-add-two-hours-to-date-variable – Bugs Oct 28 '12 at 12:52
  • or [`strtotime`](http://www.php.net/manual/en/function.strtotime.php) – air4x Oct 28 '12 at 12:53

2 Answers2

2

Use this

$expire_datetime = date('Y-m-d H:m:s',strtotime("NEXT DAY"));

or

 $expire_datetime = date('Y-m-d H:m:s',strtotime("tomorrow"));
StaticVariable
  • 5,253
  • 4
  • 23
  • 45
1
$date = date('Y-m-d H:m:s');
$newdate = strtotime ( '+1 day' , strtotime ( $date ) ) ;
$newdate = date('y-m-d',$newdate)
echo $newdate;
Arun Killu
  • 13,581
  • 5
  • 34
  • 61
  • http://php.net/manual/en/function.strtotime.php - "Using this function for mathematical operations is not advisable. It is better to use DateTime::add() and DateTime::sub() in PHP 5.3 and later, or DateTime::modify() in PHP 5.2." – Bugs Oct 28 '12 at 12:58
  • can i extend this to 1week or 1 month or 1 year for example? – itsme Oct 28 '12 at 12:58
  • he asked a minimal let him check this in manual .and he hasnt mentioned php version – Arun Killu Oct 28 '12 at 13:00