Search code examples
phpsugarcrmsugarbean

Programmatically set Start Date & Time in calls Edit view


I am trying to set the Start Date & Time automatically to the users current date and time when logging a call. This is to be set prior to loading the view.

The code is working but it is not taking into account my time zone, it is an hour behind and in uk time GMT.

How do I ensure the time zone is correct.

class CustomCallsController extends SugarController
{
    public function action_log_inbound()
{

    global $timedate;

    if(!isset($timedate) || empty($timedate))
    {
        $timedate = new TimeDate();
    }

    // get user for calculation
    $user = (empty($user)) ? $this->user : $user;

    $this->bean->direction = 'Inbound'; 
    $this->bean->date_start = $timedate->asUser($timedate->getNow(), $user);


    echo $this->bean->date_start;

    $this->view = 'edit';   
 }
}

Solution

  • The above code is correct, I had not set the time zone correctly in the user settings. It was set to GMT not GMT +1