tags:

views:

45

answers:

3

As my server is not upgreaded to php 5.3 (it is in PHP Version 5.2.11) date_sub is not working.

here is the code: $date = date_create(date('Y-m-d')); date_sub($date, date_interval_create_from_date_string('60 days')); $date1= date_format($date, 'Y-m-d');

but its ok in my localhost(which is in 5.3), but not in server(5.2.11).

Can you please tell me how can i make this date subtraction working on 5.2.11 ?

+2  A: 

Like the docs say, use DateTime::modify().

Ignacio Vazquez-Abrams
+2  A: 

$date1= date('Y-m-d', strtotime("-60 days"));

it works :)

TIT
strtotime is affected by the y2k38 bug on 32-bit platforms. The new DateTime class is not.
Emil Vikström
A: 

As the manual page says, this function works only for the PHP version >= 5.3.0.
So, you've found right solution yourself

Col. Shrapnel