PHP Calculating future date by adding days to a variable date

前端 未结 6 1789
一整个雨季
一整个雨季 2020-12-10 05:40

I was looking at this post, and it is close to what I need: PHP - How to count 60 days from the add date

However, in that post, the calculation is performed by addi

6条回答
  •  Happy的楠姐
    2020-12-10 06:40

    I see you are retriving data from a database. If you are using mysql you can do it on the select:

    Example: you need the last date of the table and this date-7 days

    select max(datefield) as ultimaf, DATE_SUB(max(datefield),INTERVAL 7 DAY) as last7
    from table
    

    It´s easy use curdate() if you want todays date.

    If you need a dynamic between that selects the count of last 7 days:

    select count(*) from table
    where DATE_SUB(CURDATE(),INTERVAL 7 DAY)<=datefield"
    

提交回复
热议问题