AnsweredAssumed Answered

Get an effective TimeDate from a SugarBean field

Question asked by Eric Houvenaghel on Feb 21, 2018
Latest reply on Feb 22, 2018 by Eric Houvenaghel

I must be missing something obvious, but it seems that I'm unable to find a way to get the TimeDate object from the value of a SugarBean field.

Let's say I get a specific Lead with this kind of call:

$lead = BeanFactory::retrieveBean('Leads', "18bfc69e-8cd4-11e7-ad08-000c29b1a36e");

then any call to this:


will return a string value: "2017-08-29 16:05" (note the absence of seconds).

So then if I try to use such value to create a SugarTimeDate:

$TimeDate = new TimeDate();
$SugarTimeDate = $TimeDate->fromDb($lead->date_entered);

it will return false, since the value provided to fromDb() is not in the proper format (the seconds are missing).


When looking at the SQL table with Toad, I can see that the information is effectively stored in the database as a DateTime. But the sugarbean object provideds it as a text with a format that is incomplete.


So how can you get the effective SugarTimeDate, TimeDate or DateTime from a Field in a given SugarBean, ideally as an object?

I searched, and all the example I found was about creating a new date object from Now to set to a field in a SugarBean, but none to set a datetime field from an existing datetime field.


Any hints would be highly appreciated.