13. Date, Time, and Color Fields | Field Forge - Custom Fields, Built for Speed
Download Log in

13. Date, Time, and Color Fields

Developer Guide

Fields for temporal data and visual styling values.

Date Picker

Returns a date string formatted per the return_format setting.

php
$date = get_field( 'event_date' );
// Stored internally as 'Y-m-d' (e.g., '2024-12-25').
// `return_format` controls what get_field() returns: when unset, you get the
// raw stored value (`Y-m-d`); when set to a PHP date format like `F j, Y`,
// the field re-formats automatically.

echo '<time datetime="' . esc_attr( $date ) . '">' . esc_html( $date ) . '</time>';

// Parse and reformat ad hoc
$raw = get_field( 'event_date' );
$timestamp = strtotime( $raw );
echo '<p>Event: ' . date_i18n( 'l, F j, Y', $timestamp ) . '</p>';

// Compare dates
$event_date = get_field( 'event_date' );
$now = current_time( 'Y-m-d' );
if ( $event_date && strtotime( $event_date ) >= strtotime( $now ) ) {
    echo '<span class="upcoming">Upcoming</span>';
} else {
    echo '<span class="past">Past Event</span>';
}

Time Picker (PRO)

Returns a time string.

php
$time = get_field( 'opening_time' );
// Returns: formatted string per return_format, e.g., '09:00:00' or '9:00 AM'

echo '<span class="time">' . esc_html( $time ) . '</span>';

// Combine date and time
$date = get_field( 'event_date' );
$time = get_field( 'event_time' );
echo '<p>Event: ' . esc_html( $date ) . ' at ' . esc_html( $time ) . '</p>';

Color Picker

Returns a hex color string (or rgba if opacity is enabled).

php
$color = get_field( 'brand_color' );
// Returns: '#FF5733' or 'rgba(255,87,51,0.8)' if opacity enabled

echo '<div style="background-color: ' . esc_attr( $color ) . ';">Colored block</div>';

// Use as CSS custom property
$primary = get_field( 'primary_color', 'options' );
$secondary = get_field( 'secondary_color', 'options' );
echo '<style>:root { --color-primary: ' . esc_attr( $primary ) . '; --color-secondary: ' . esc_attr( $secondary ) . '; }</style>';

Forge AI Assistant Online

Hi! I'm the Field Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs