KJ Saxena
KJ Saxena

Reputation: 21838

What date/time functions to use for PHP 5.2

The DateTime, DateInterval etc. classes are not available at the server I am using (PHP 5.2)

Which functions should I use instead?

Upvotes: 4

Views: 3338

Answers (4)

Gordon
Gordon

Reputation: 317089

If you look at the PHP Manual pages for DateTime and DateInterval, you can see which version is required for a specific function right below the method name, e.g.

DateInterval::createFromDateString
(PHP 5 >= 5.3.0)

indicates this method is available from PHP5.3 on.

Like already pointed out in other answers, some of the DateTime (but not DateInterval) methods are already regularly available as of 5.2. As an alternative, you can use the regular Date functions. Note that many of the functions prefixed with date_ and timezone_ are aliases for their respective OOP counterparts in DateTime and DateTimezone, so you will not be able to use them, if you cannot use them now.

If you want an OO lib for dates, have a look at Zend_Date or PEAR_Date.

Upvotes: 2

Tobias
Tobias

Reputation: 737

Note: Experimental DateTime support in PHP 5.1.x Although the DateTime class (and related functions) are enabled by default since PHP 5.2.0, > it is possible to add experimental support into PHP 5.1.x by using the following flag before configure/compile: CFLAGS=-DEXPERIMENTAL_DATE_SUPPORT=1

As can be read on php.net So DateTime should be available on 5.2.0

Upvotes: 0

casraf
casraf

Reputation: 21694

Here's a reference of the date/time functions you can use.

Upvotes: -1

Frank Farmer
Frank Farmer

Reputation: 39356

DateTime is part of PHP 5.2 core; however 5.3 added some more methods that weren't available in 5.2

DateInterval, on the other hand, appears to be unique to PHP 5.3.

Are you sure DateTime isn't available at all? Are you sure you're using PHP 5.2?

Try calling class_exists('DateTime') and phpversion()

Upvotes: 3

Related Questions