1. Documentation
  2. Advanced
  3. Date Fields

Date Fields

In some blocks, shortcodes or widgets you will find fields with an annotation that they have support to any PHP date format.

It means that those fields accept any PHP date format in order to generate a specific or relative date in order to (commonly) filter the results of the block, shortcode or widget you are working with.

Specific date

You can pass specific dates in a format of “year-month-day” (known in PHP as Y-m-d) like 2017-07-20 (The GamiPress official release’s date).

Developers note: In addition, those fields has support to receive a specific date timestamp.

Relative dates

One of the most value functionalities is the ability to pass a relative format in order to generate a relative date.

There are a few examples:

  • Today: “today” or “now”
  • Yesterday: “yesterday” or “-1 day”
  • 10 days ago: “10 days ago” or “-10 days”
  • 2 weeks ago: “2 weeks ago”, “-2 weeks” or “-14 days”
  • First day of past week: “first day of previous week” or “first day of -1 week”
  • Past month: “1 month ago”, “previous month” or “-1 month”
  • First day of 2 months ago: “first day of 2 months ago”
  • 2 years ago: “2 years ago” or “-2 years”

There is a full list of relative formats you can use.

Custom period fields

Some blocks, shortcodes or widgets bring you the ability to provide a custom period with a start and end dates.

The unique annotation to keep in mind with those fields is to ensure to provide a older start date than the end date.

Also, if you want to setup a period until today you can set “now” as end date.
For example, to provide a period from past 10 days until today you need to provide the start date as “-10 days” and end date as “now”.

Official PHP documentantion

Of course, this page can’t cover everything you can perform with awesome utility since the number of formats and combinations could be unlimited.

For that we recommend you to check the official PHP date format documentation where you will find date formats grouped in:

How can we help?