Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increment date with 1 (day/year) in PHP?

Tags:

php

I have a date stored in an array:

$this->lines['uDate']

The format of the date is not fixed. I can be changed with this:

  define('DATETIME_FORMAT', 'y-m-d H:i');

How can I increment my uDate with a certain number of days or years?


My question is related to this one:
increment date by one month
However, in my case the date format in dynamic.
So, can I do this?

$time= $this->lines['uDate'];
$time = date(DATETIME_FORMAT, strtotime("+1 day", $time));
$this->lines['uDate']= $time;
like image 564
Server Overflow Avatar asked Feb 24 '23 18:02

Server Overflow


1 Answers

date_add()

and consider changes like:

define(DATETIME_FORMAT, 'y-m-d H:i');

$time = date(DATETIME_FORMAT, strtotime("+1 day", $time));
like image 193
bensiu Avatar answered Mar 07 '23 00:03

bensiu