[wp-trac] [WordPress Trac] #48936: Remove mysql2date() usage from core
WordPress Trac
noreply at wordpress.org
Tue May 6 01:34:13 UTC 2025
#48936: Remove mysql2date() usage from core
------------------------------------------+------------------------------
Reporter: Rarst | Owner: pbearne
Type: enhancement | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Date/Time | Version:
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+------------------------------
Comment (by sukhendu2002):
I think we can use wp_date() for most cases. It handles timezones
properly.
For displaying dates to users, we'd do something like:
{{{#!php
$datetime = date_create($date_string, wp_timezone());
wp_date($format, $datetime->getTimestamp());
}}}
For UTC time outputs (like in feeds), gmdate() works well:
{{{#!php
$timestamp = strtotime($date_string);
gmdate($format, $timestamp);
}}}
For comparing dates, it's cleaner to just create DateTime objects and
compare them directly rather than converting to timestamps.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48936#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list