Add days to current date from MySQL with PHP

后端 未结 4 1499
别那么骄傲
别那么骄傲 2021-01-18 11:59

I have a fixed date from MySql

startDate = 07/03/2011

I wanted to add 60 days on top this date to have an endDate.

$startDa         


        
4条回答
  •  忘掉有多难
    2021-01-18 12:39

    In addition to PHP solutions others are providing, you can create the endDate right inside of MySQL and save yourself some of the trouble:

    SELECT startDate, DATE_ADD(startDate, INTERVAL 60 DAY) AS endDate FROM table;
    
    -- Or by months (not exactly the same thing)
    SELECT startDate, DATE_ADD(startDate, INTERVAL 2 MONTH) AS endDate FROM table;
    

    Relevant documentation here...

提交回复
热议问题