datetime field wouldn't show the time in PDF/Email, How to show datetime correctly instead of showing only date

I have inserted a datetime in PDF/Email template but it will only show the date without the time.

I have added $sugar_config[‘time_formats’][‘H.i.s’] = ‘23.00.00’; in config_override.php but what shall I do next?

Please kindly advice. Thanks!

You will need to give us more information than that!

For example, In a Quote PDF Template, I have inserted a Date Created ($aos_quotes_date_entered) field in the template. When generating the pdf or email, it will only show as 19/1/2015 instead of 19/1/2015 18:16PM.

Hope it clarifies.

This appears to be a bug. We will add this to the list of bugs to be fixed in a later release.

is there a temporary fix method?

It seems that the problem is not yet resolved in version 7.4.3.

In the email template, connected to the meetings module, uitilizzo field $meeting_date_start for display, eg, 26/11/2015 17:15.
Instead displays only 26/11/2015.
Is there a way to have the replacement of all the value 11/26/2015 17:15?

Thanks for the support

Any updates regarding this issue?

I look forward for any response.

Many Thanks :slight_smile:

Is there any update to this?
Actually I think a better software architecture would be to split into a date field and a time field. There is no need for a date-time field.
Separating date and time will allow for a lot more flexibility.

Has anyone found a work around for this?

I found the root cause of the problem.
In /modules/AOS_PDF_Templates/templateParser.php
in line 108 there is an if statement which looks for the word date (see below).
So basically, if any field name has “date” in it, the parser modifies how the variable should be displayed.
The workaround for now is that rename your field without the word “date” anywhere in it.
Hopefully this issue can be addressed in the next update.

    if (strpos($name, 'date') > 0 || strpos($name, 'expiration') > 0) {
        if ($value != '') {
            $dt = explode(' ', $value);
            $value = $dt[0];
        }

Also not a good idea to have any field names with the word ‘expiration’ in it.

I found the quick fix for this issue, may be helpful for you.
In /modules/AOS_PDF_Templates/templateParser.php

Search for code

if (strpos($name, 'date') > 0 || strpos($name, 'expiration') > 0) {
if ($value != '') {
$dt = explode(' ', $value);
$value = $dt[0];
}

and make it

if (strpos($name, 'date') > 0 || strpos($name, 'expiration') > 0) {
if ($value != '') {
   $value = $value;
}

actually, it explodes the string into array by space and then just takes the first array whereas time is in the second array so it concatenate both arrays.

@pavan_redian are you sure that is the right code? Are you really just assigning $value to $value? :huh:

Please follow the code below-

In /modules/AOS_PDF_Templates/templateParser.php:


if (strpos($name, 'date') > 0 || strpos($name, 'expiration') > 0) {
	if ($value != '') {
		$dt = explode(' ', $value);
		$value = $dt[0];
		if(asset($dt[1])){
		    if (strpos($dt[1], 'am') > 0 || strpos($dt[1], 'pm') > 0) {
		        $value = $dt[0].' '.$dt[1];
  		    }
		}
	}
}
1 Like

Thanks for that.

Is this something you can put together into a Pull Request on GitHub as a code contribution?

Sure

1 Like