Can anyone tell what is wrong with the code.

$timezone = "Asia/Karachi"; 
$date = new DateTime($when_to_send, new DateTimeZone($timezone));
$date = $date->setTimezone(new DateTimeZone('GMT')); 
$when_to_send = $date->format('Y-m-d H:i:s');

error is: Call to a member function format() on a non-object

Accepted Answer

$date = $date->setTimezone(new DateTimeZone('GMT'));

Makes the $date variable null, you should just call it:

$date->setTimezone(new DateTimeZone('GMT'));

Written by cpf
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki