[wp-trac] [WordPress Trac] #48740: Add constant for database date format

WordPress Trac noreply at wordpress.org
Wed Nov 20 13:08:57 UTC 2019


#48740: Add constant for database date format
-------------------------+--------------------------------------
 Reporter:  Rarst        |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Date/Time    |    Version:
 Severity:  normal       |   Keywords:  needs-patch dev-feedback
  Focuses:               |
-------------------------+--------------------------------------
 A lot of core Date/Time code is dealing with `Y-m-d H:i:s` format, as
 stored for posts and other objects in database.

 This is effectively a so-called "magic" string, which is not self-
 explanatory and prone to user error if typed by hand (I messed up `i` with
 `m` for minutes more than once probably).

 Since there is no upstream PHP constant for this format, I suggest we
 introduce one in core and use it in place of magic string:

 {{{#!php
 define( 'WP_DATE_MYSQL', 'Y-m-d H:i:s' );
 }}}

 Not absolutely sure about the name, I used `DATE_MYSQL` as class constant
 before, but `WP_DATE_DATABASE` might be more appropriately generic. To my
 knowledge there isn't a specific ISO or RFC designation for such format.

 If there is agreement on the need and the name I'll work on a patch for
 replacement and switch from strings in core.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48740>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list