Skip Navigation

[Resolved] Datepicker returns weird numeric value

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

Problem: I am trying to display a date from a Types custom field, but instead I see a long number.

Solution: Types date fields store information as Unix timestamps in the database. To show a formatted date like "6 Januari" you can use the format option in a Types field shortcode:

[types field='datum' style='text' format='j F'][/types]

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/#date
http://php.net/manual/en/function.date.php

This support ticket is created 6 years 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 6 replies, has 2 voices.

Last updated by jelle-jacobd 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1164771

Hi, I'm trying to read a Toolset custom field with in this case wpcf-date but it returns a strange numeric value like 14065789. What am I doing wrong?

#1165059

You're not doing anything wrong. This value is called a Unix timestamp, and it's a standard way of saving dates. You can apply a format that number to show something like "December 12, 2018" or "12/12/2018", etc., or you can use the Unix timestamp to make date comparisons or conditional HTML criteria. We have some documentation available here: https://toolset.com/documentation/customizing-sites-using-php/functions/#date

If you use the Types field shortcode, you can output a formatted date per the instructions in the document above. If you use the wpv-post-field shortcode, you can't add formatting as easily. It would require multiple nested shortcodes.

#1165445

That's a relieve, thanks for the info. How should I use the Types field shortcode outside of toolset or a page. I'm using a grid builder integrated in my theme. It has een option to add wpv-post-field and an html field for 3d-party code like Types field shortcode but is just renders the shortcode not the value. Like this: {!{types field='datum'}!}{!{/types}!}

#1165652

Can you try adding the shortcode with square brackets instead of curly brackets?

[types field='datum'][/types]
#1165656

Thanks, that worked. How should I modify this shortcode to get the date like: 6 januari ?

#1165667

You can use any of the date formatting options from the PHP date manual, but I don't think there is a lowercase month name. You can get 6 Januari with the format j F:

[types field='datum' style='text' format='j F'][/types]

A lowercase month name will require custom PHP.

https://toolset.com/documentation/customizing-sites-using-php/functions/#date
http://php.net/manual/en/function.date.php

#1165668

My issue is resolved now. Thank you!