Displaying Date-Time picker
The date/time picker (e.g ACF DatePicker) is a field type that provides a calendar-based interface for editors to choose a date and/or time, as opposed to a simple text input. There are various date and time formats, such as European (e.g., dd/mm/yyyy) or US (e.g., mm/dd/yyyy), as well as options for displaying time in either 12-hour or 24-hour formats.
Advanced Views natively supports the following Date-Time types:
ACF: any DatePicker, DateTimePicker, TimePicker field
MetaBox: any Date, DateTime field
Pods: any Date, DateTime, Time field
1. How to display a Date-Time field
Add any Binary choice field
Save the Layout, copy its embedding shortcode
Embed Layout: paste the shortcode inside the target place
By default, Advanced Views displays the date in the format you've set up in the field settings, either as the 'Return' or 'Save' format. You can customize the Layout template to change the output:
2. Date format manipulations
When working with dates, it's important to consider the variable type. Strings containing dates and Date objects are distinct entities, and you should keep the following in mind:
Date objects cannot be displayed directly; you need to convert them into strings for this purpose.
When using conditional statements, like
if, you cannot directly compare date strings; you should first convert them into Date objects for comparison.
Tip: When you make the date manipulations, we recommend using the timestamp property of the date field.
This will save you from dealing with date parsing issues. For example, both US (e.g., mm/dd/yyyy) and European (e.g., dd/mm/yyyy) formats use the same delimiter, so the European format will be ignored in favor of the US format. This behavior is the default behavior of the strtotime PHP function.
2.1) Inside Twig templates
Date filter (for output)
Converts a Date object into a string based on the specified format. If you provide a string, the filter will automatically parse the date using strtotime and then convert it into a string in the requested format.
Date_modify filter (for modification)
Modifies a Date object according to the argument provided and returns the modified Date object. If you pass a string, the filter will automatically parse the date using strtotime.
Keep in mind that this function returns a Date object, not a string. If you want to display the modified date, you should use the "date" filter to print the Date object in a specific format.
Date function (for comparison)
Converts a string into a Date object, which is useful for comparison purposes.
Keep in mind that this function also returns a Date object, not a string. If you want to display the Date object, you should use the "date" filter to print it in a specific format.
Available date formats
you can use any formats with the |date filter
you can use most of the available date formats for the date() function. For example, "m-d-Y" (10-20-2011), "M d, Y" (October 20, 2011), or "d.m.Y" (20.10.2011).
Use 'datepicker.timestamp|date("d-m-Y")' as a safe way to avoid date parsing issues described above.
3. Multilingual dates
By default, PHP displays date-related symbols (such as 'a.m.') in English. Advanced Views utilizes the 'date_i18n' WordPress function, which supports multiple languages, so you don't need to concern yourself with translating date-related symbols.
Last updated