Asked 1 years ago
9 Jun 2022
Views 508
debugger

debugger posted

how to add days to given date in php ?

how to add any numbers days to date in PHP ?

suppose , i want to add 5 days to current date or i want to subtract some days from current or given date
sqltreat

sqltreat
answered Oct 8 '21 00:00

time()
By using time() function in PHP
time() return current timestamp and by adding n days to it lead to time of after n(any number) days
for example :
add 1 days to the current date.

date('Y-m-d',time()+3600*24*1);


add 2 days to the current date.

date('Y-m-d',time()+3600*24*2);


add 3 days to the current date.

date('Y-m-d',time()+3600*24*3);



strtotime()
By using strtotime() function in php
strtotime() function convert string to time .

add 1 days to the current date.

date('Y-m-d',strtotime("+1 days"));


add 2 days to the current date.

date('Y-m-d',strtotime("+2 days"));


add 3 days to the current date.

date('Y-m-d',strtotime("+3 days"));



add 1 days to any date.

date('Y-m-d',strtotime("2021-10-19 +1 days"));


add 2 days on any date.

date('Y-m-d',strtotime("2021-10-19 +2 days"));


add 3 days to any date.

date('Y-m-d',strtotime("2021-10-19 +3 days"));


Post Answer