time () function php

1

I am paging some purchases that have specific dates, and when I pass as a parameter that a date should be < that date("Y-m-t", time() + 14*24*60*60) , which in the case would have to be 2 weeks, he pages me 1 month. According to the php doc, 24*60*60 is 1 day, so date("Y-m-t", time() + 14*24*60*60) would be 14 days / 2 weeks. Does anyone understand why this is so?

    
asked by anonymous 18.09.2015 / 16:01

2 answers

2

If you want to use only functions, strftime() and strtotime() solve as well.

echo strftime('%Y-%m-%d', strtotime('+2 weeks'));
    
18.09.2015 / 16:17
1

Instead of using date() you can use DateTime which has several interesting methods.

Doc PHP - DateTime

Using the method add() - Doc DateTime - Add

Example:

$now = new DateTime();

echo $now->format('d/m/Y H:i:s'); // exibe 18/09/2015 10:12:40

echo '<br />';

$now->add(new DateInterval('P2W')); 

echo $now->format('d/m/Y H:i:s'); // exibe 02/10/2015 10:12:40
    
18.09.2015 / 16:11