Skip Navigation

[Resolved] Custom date fields are displaying in UNIX format instead of MM DD, YYYY

This thread is resolved. Here is a description of the problem and solution.

Problem: I am using types_render_field to display custom dates, but the values are shown as timestamps after updating the plugins.

Solution: For now, you can apply the style attribute to the types_render_field arguments array, or you can apply the patch files in the linked erratum post.

Relevant Documentation:
https://toolset.com/errata/types-fields-are-not-displayed-properly-using-types_render_field/

This support ticket is created 6 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by thoraldM 6 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#954675

I am trying to display custom date fields the normal way and instead I'm getting the UNIX format of the dates.

Link to a page where the issue can be seen: hidden link

I expected to see (underneath the Bent Spun graphic):

The tunes that rocked the hebdomad for the tracking period beginning July 16, 2018 and ending July 22, 2018.

Instead, I got:

The tunes that rocked the hebdomad for the tracking period beginning 1531699200 and ending 1532217600.

#954679

Here is the code I am using to display the date fields mentioned above.

div><i>The tunes that rocked the hebdomad for the tracking period beginning <?php echo types_render_field("tracking-period-begin-date", array(output=>"normal")); ?> and ending <?php echo types_render_field("tracking-period-end-date", array(output=>"normal")); ?>.</i><p>&nbsp;</p></div>
#954690

Hi, try these options in the arguments array instead:

echo types_render_field("tracking-period-begin-date", array("style"=>"text", "format"=>"F d, Y" ));
...
echo types_render_field("tracking-period-end-date", array("style"=>"text", "format"=>"F d, Y" ));

"output"=>"normal" is the default, so there's no need to include that. "format" is how you define the date format to apply to the timestamp. "F d, Y" will produce the format "July 24, 2018". Without the "style"=>"text" option, the timestamp will be displayed with no formatting.
https://toolset.com/documentation/customizing-sites-using-php/functions/#date

Let me know if the problem is not fully resolved and I can offer more assistance.

#955331

Thanks Christian! Your solution worked! It's weird that the old code used to work, and then after I updated my Toolset today, it stopped working and started showing the unformatted UNIX dates instead. I guess something was changed in the Toolset code. Thanks again!

#955508

Okay thanks for the update. It seems that a change was introduced that caused existing shortcodes to behave differently in the new versions. We have a ticket in place with our developers to fix the backwards-compatibility issue here, but for now the best solution is to use the style and format attributes I described.

#955559

Our developers have just confirmed this issue will be fixed in the next release, so existing date shortcodes will continue to function as expected. I'll let you know when that release is available.

#955638

Thanks Christian! :-*

#956522

Quick update to let you know a patch has been created. Feel free to install the patch here, or wait until the next plugin release. https://toolset.com/errata/types-fields-are-not-displayed-properly-using-types_render_field/

#956631

Thanks very much Christian!