Rob
Rob

Reputation: 1539

Call to undefined method DateTime::setTimeStamp()

I've been using setTimeStamp to convert a Unix Timestamp to a datetime in the following way:

$startHireConverted = strtotime($startHire); // converts start hire to time
$endHireConverted = strtotime($endHire); // converts end hire to time

$startdt = new DateTime();
$startdt->setTimeStamp($startHireConverted);
$mysql_startdate = $startdt->format("Y-m-d H:i");

This was working nicely, but recently I've put the website live and the version of PHP can only be 5.2.12 which doesn't support the setTimeStamp method.

I've tried changing setTimeStamp to format which is getting rid of the errors and converting the datetime but it is changing it to the current datetime - 5 hours for some reason rather than the date stored in $startHire.

$startdt->format($startHireConverted);

Any ideas on how to get around this problem?

$startHire starts out as a string version of datetime.

Thankyou

Upvotes: 2

Views: 2754

Answers (1)

Czechnology
Czechnology

Reputation: 14992

I don't think you need to do the step with unix timestamp at all:

$startdt = new DateTime($startHire);

PHP manual: DateTime::__construct

But that might depend on the format you're getting $startHire in. See Supported Date and Time Formats.

Upvotes: 4

Related Questions