AnsweredAssumed Answered

How to compare datetime functions?

Question asked by on Oct 8, 2014
Latest reply on Oct 2, 2015 by Richard West
How do I compare date_start to time() ?  Or convert it to something comparable (such as ISO time or seconds since epoch) ?  There are a bunch of SugarDate and DateTime classes, but of course no documentation, so maybe an answer here can help other developers.

Say $c1 is a call, then:
php > echo $c1->date_start;
10/07/2014 03:00pm
php > echo $c1->fetched_row['date_start'];
2014-10-07 19:00:00
php > echo date('Y-m-d h:i:s', time());
2014-10-08 10:06:04
 So the date_start time is in whatever format the user chose, not textually comparable in this case.  The fetched_row value is, but won't exist for a new record or be the incoming value in before_save hook.

How do I convert or compare ?

When a call is created, if it's in the past I'd like to automatically set it to 'Held' (iff current, default status is 'Planned').  I'd put this in my 'before_save' hook (where I already have some other logic).