Get an effective TimeDate from a SugarBean field

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:

$lead->date_entered

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.


Parents
  • Thanks a lot Patrick.

    Just tried, and this workaround does work.

    So when

    $lead->date_entered

    returns "2017-08-29 16:05", the other one

    $lead->fetched_row['date_entered']

    returns "2017-08-29 16:05:56", which is what is expected.

    Note that this will be the same for any DateTime field that can exist in a record, and not only for this "date_entered" special field, which value is set by the bean object.

    Another workaround I found was to get the DateTime values trough a SugarQuery request, which returns the effective value of the field itself in the array. But this is a bit overkill...

Reply
  • Thanks a lot Patrick.

    Just tried, and this workaround does work.

    So when

    $lead->date_entered

    returns "2017-08-29 16:05", the other one

    $lead->fetched_row['date_entered']

    returns "2017-08-29 16:05:56", which is what is expected.

    Note that this will be the same for any DateTime field that can exist in a record, and not only for this "date_entered" special field, which value is set by the bean object.

    Another workaround I found was to get the DateTime values trough a SugarQuery request, which returns the effective value of the field itself in the array. But this is a bit overkill...

Children
No Data