Add 30 days for date in db

半世苍凉 提交于 2019-12-12 19:25:08

问题


I have publish up date and publish down date in my DB. Currently they are both same dates.

How do I change it (during mysql insert) so publish down date is 30 days past publish up date.

I am using $pubDate

Thanks


回答1:


You can use DATE_ADD():

DATE_ADD(my_date, INTERVAL 30 DAY)



回答2:


in php, before inserting you can use strtotime(): if the publishDown date is a timestamp:

$publishDown = strtotime("+30 days",$publishDown);

otherwise you may have to use mktime to get it in the right format



来源:https://stackoverflow.com/questions/1609377/add-30-days-for-date-in-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!