duanlijia5864 2014-12-01 18:20
浏览 43

根据php / joomla中的句点计算日期

Anyone knows how to calculate date based on number of week/Month/Year?

suppose if i set the period as 2 weeks, I should get the date 2 week after the current date. If the period is 3 weeks, then, I should get 3 week after current date. Similarly for month and year as well. Can anybody please help with reference code? I am not able to implement this. Is there any predefined function for this?

  • 写回答

1条回答 默认 最新

  • doutenglou6588 2014-12-01 18:35
    关注

    I'm not quite clear on what you're trying to get, but take a look at this answer at joomla.stackexchange.com to see the PHP-esque date calculations that are possible. It's about quarters, but with variations like strtotime uses, you should be able to get what you need.

    $date = date("Y-m-d");// current date
    
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week");
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days");
    
    评论

报告相同问题?