i have some problem with strtotime , when i try to addimg 2 month to my current date
Example :
'2014-12-16 13' => date('Y-m-d H');
$compare_date = date('Y-m-d H:i',strtotime('2014-12-16 13'.'+2 month'));
i have some problem with strtotime , when i try to addimg 2 month to my current date
Example :
'2014-12-16 13' => date('Y-m-d H');
$compare_date = date('Y-m-d H:i',strtotime('2014-12-16 13'.'+2 month'));
I tested it in phpFiddle
It works if you specify minutes (Based on this code)
$compare_date = date('Y-m-d H:i',strtotime('2014-12-16 13'.'+2 month'));
You said H:i
so if you use:
$compare_date = date('Y-m-d H:i',strtotime('2014-12-16 13:00'.'+2 month'));//Note the :00
it works for me.
EDIT1:
Without H:i
$compare_date = date('Y-m-d',strtotime('2014-12-16'.'+2 month'));
EDIT2:
o-W
this works a little for me:
$compare_date = date('o-W',strtotime('2014-12-16'.'+2 month'));
EDIT3:
As comment says, get rid of dot
$compare_date = date('o-W',strtotime('2014-12-16 +2 month'));
You're using strtotime wrong. When using relative time (+2 month) you should provide a timestamp as second parameter (current timestamp is the default value).
$compare_date = date('Y-m-d H:i',strtotime('+2 month', strtotime('2014-12-16 13:00')));
Have you tried
$compare_date = date('Y-m-d H',strtotime('2014-12-16 13'.'+2 month'));
Instead of:
$compare_date = date('Y-m-d H:i',strtotime('2014-12-16 13'.'+2 month'));
Beware with using +month notice the behavior below if the month after has less days
echo date( "Y-m-d", strtotime( "2009-01-31 +1 month" ) ); // PHP: 2009-03-03
echo date( "Y-m-d", strtotime( "2009-01-31 +2 month" ) ); // PHP: 2009-03-31