With the new TimeDate changes that came in Sugar 6.2, there’s been a bit of confusion on how to best set date values when using logic hooks. I saw this question recently on our internal mailing list…
What’s the best way to handle setting the due date on a task before it gets saved in a logic hook?
This is what i’m going to do so in the logic hook
$timedate = TimeDate::getInstance(); $end_date = new SugarDateTime('+4 days'); $task->date_due = $timedate->asUser($end_date, $GLOBALS['current_user']);
Our Application Architect Stas Malyshev jumped right on this, providing this code solution:
You should use DB time format, as before_save is called after conversion hooks. I would advise doing this:
$task->date_due = TimeDate::getInstance()->getNow(true)->modify("+4 days")->asDb();