Quite recently, I faced an issue wherein I have to push some calculated date(based on some algo) to the date field on EditView of a custom module.
My custom function calculated date in dd/mm/yyyy format but the user can have any possible date formats defined by SugarCRM.
Before pushing my calculated date i need to format this date according to user’s settings.
I did little modifications in the code and hurrah it solved my problem
global $current_user; // Instantiate the TimeDate Class
$timeDate = new TimeDate();
$sampleDate = '2014-08-28'; // Sample date.
// Call the function
$FormatedDate = $timeDate->to_display_date($sampleDate, true, true, $current_user);
echo "Date->".$FormatedDate;
//If you want to get time too use the following code.
$sampleDateTime = '2014-08-28 08:00:00'; // Sample date.
// Call the function
$FormatedDateTime = $timeDate->to_display_date_time($sampleDateTime, true, true, $current_user);
echo "DateTime->".$FormatedDateTime;
Hope you find this blog post helpful.
Feel free to add comments and queries, that helps us to improve the quality of posts.
You can contact us at [email protected]
Thank you.