Subtracting a certain number of hours, days, months or years from date

后端 未结 3 1660
Happy的楠姐
Happy的楠姐 2020-12-03 05:49

I\'m trying to create a simple function which returns me a date with a certain number of subtracted days from now, so something like this but I dont know the date classes we

3条回答
  •  無奈伤痛
    2020-12-03 06:37

    Try to use datetime::sub

    Example from the docs (linked):

    format("d-m-Y H:i:s").'
    '; date_sub($date, new DateInterval("P5D")); echo '
    '.$date->format("d-m-Y").' : 5 Days'; date_sub($date, new DateInterval("P5Y5M5D")); echo '
    '.$date->format("d-m-Y").' : 5 Days, 5 Months, 5 Years'; date_sub($date, new DateInterval("P5YT5H")); echo '
    '.$date->format("d-m-Y H:i:s").' : 5 Years, 5 Hours'; ?>

提交回复
热议问题