How To save date and time value in date and time field in sugarcrm using before save logic hook ?
If you want to populate current date time value in date time field then we can achieve this by adding formula in date time field from studio.
If you want to set date time field with any other value (other than current date time) then you have to write code in create.js file in respective module.
I am trying to fetch date create/ date modified from (any table) database using custom query query in sugarcrm entry point but accurate date not fetched using query.
Exm. date_create-03-03-2020 03:23:45 (CRM Module display date created)
but when i select to fetch this date using custom Query in sugarcrm date create mismatch
so problem is that how we can fetch same date and time as crm create shows.
If we are fetching date time value from database, will get the value with the difference of 5 hours 30 minutes. So, to get exact date time value as shown on sugar UI we have to change/modify the date format through code.
date('d-m-Y H:i:s',strtotime('+5 hour +30 minutes',strtotime(date_value)));
in place of 'd-m-Y H:i:s' you can use your required date time format.
date_value - pass the date time field value (retrieved date time value from query)
Also please refer the below link to format the date time value using sugar default method.
Please let me know in case of any queries.
Based on what was described, it appears to me that you might be retrieving data with SQL directly from the database which is not something I would encourage. Sugar stores date times in GMT, not on your local timezone. That's why you see a difference in timezone offset.
You should use instead Sugar Beans to retrieve the information you need, so that the date times will be converted on the logged in user's timezone settings. As a starting point you could look at this page of the manual and see how you go.
Also, as on the original description it was mentioned you are working with logic hooks, you can interact with the bean object directly by using the first hook parameter as the current bean, without having to retrieve anything else. See this page for more details.
If you are using entry points instead (as it was mentioned on the last post), entry points most likely are non-authenticated. Perhaps if that is indeed the case, it would be a good idea to re-think the approach of the customisation, if you are attempting to expose data to the outside world without authentication as that would not be safe.
Hope the pointers will help you achieve what you are after
Principal Technical Advisory Manager