Skip to content
Radoslav Georgiev edited this page Oct 21, 2018 · 2 revisions

Purpose

The Date, Date-Time & Time fields allow users to pick a date/time through a jQuery date-picker.

date-time-fields

Settings

There are no adjustable settings for those fields.

Date format

All of those fields use the format, set in WordPress. You can adjust it in Settings > General.

Usage

When you use the get_value or get_sub_value functions, the returned value will be a UNIX timestamp, which you can use with date functions like date_i18n and etc.

If you use the_value, get_the_value, the_sub_value and get_the_sub_value functions, they will display/return a value based on your website's settings. If you prefer to change this format, please use a get_* function in combiation with date_i18n.

<h3>Date field:</h3>
<p>
	Auto-formatted value:
	<?php the_value( 'my_date_field' ) ?>
</p>
<p>
	Manually formatted value:
	<?php echo date_i18n( 'Y-m-d', get_value( 'my_date_field' ) ) ?>
</p>

<h3>Date-Time field:</h3>
<p>
	Auto-formatted value:
	<?php the_value( 'my_date_time_field' ) ?>
</p>
<p>
	Manually formatted value:
	<?php echo date_i18n( 'Y-m-d H:i', get_value( 'my_date_time_field' ) ) ?>
</p>

<h3>Time field:</h3>
<p>
	Auto-formatted value:
	<?php the_value( 'my_time_field' ) ?>
</p>
<p>
	Manually formatted value:
	<?php echo date_i18n( 'H:i', strtotime( '2017-01-01 ' . get_value( 'my_time_field' ) ) ?>
</p>

As you can see the only exception is the value of the Time field. It will always return a 24-hour format H:i string, which consists of an hour and a date. In order to use this value with the date_i18n function, you need to convert the time to an actual timestamp. To do that, we are using a fake date and processing the value through strtotime().

Clone this wiki locally