Skip to toolbar

When using SORT on a Date/Time field, the numbers in Post Meta are stored as LONGTEXT so you need to cast them as Date & Time Fields first. Typically, they are stored as yyyy-mm-dd hh:mm:ss but if you’re doing date/time math or sorting, you’ll solve a lot of issues by using CAST:

CAST( date_time_field.meta_value AS DATETIME ) DESC

With MySQL, the available options for CAST are DATE, DATETIME and TIME