Converting between different date formats

These can be dropped into your functions.php to enable various shortcodes.

Sortable Date

This one takes a date string as its input and will display a date that is in the order Year Month Day, which can be used when you need to sort a column of dates numerically, for example.

[sortable_date]01/12/2016[/sortable_date]

Output: 20161201

Convert Sortable Date to UK Date

This converts the date from Ymd to d/m/Y

[sortable_date_to_uk]20161201[/sortable_date_to_uk]

Output: 01/12/2016

Age in Years

This one takes a date string (e.g. a date of birth) as its input and will display the age in years as a number. For example:

[date_to_age]01/12/2016[/date_to_age]

Output: 2

Leave a Reply