Make WordPress Core

Opened 5 years ago

Last modified 16 months ago

#46210 new enhancement

Add helpers for default/empty datetime value

Reported by: johnjamesjacoby's profile johnjamesjacoby Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Database Keywords: has-patch
Focuses: Cc:


Typing 0000-00-00 00:00:00 is error prone, and tedious.

There are a few dozen usages of it sprinkled through-out WordPress. Hundreds of plugins also.

I offer up the idea of 2 helper functions:

  • __return_empty_datetime() that simply returns 0000-00-00 00:00:00
  • is_empty_datetime( $datetime = '' ) to check if a variable is empty() or 0000-00-00 00:00:00

Change History (5)

#1 @johnjamesjacoby
5 years ago

Beware: the NO_ZERO_DATES MySQL mode rabbit hole is very deep.

WordPress doesn't use null as a default value in datetime columns for legacy reasons, and I'm not suggesting we try to support it here. Mostly, I am just sick of typing 0000-00-00 00:00:00 in my own related code, and rewriting the same helpers for avoiding empty datetime values.

#2 @johnbillion
5 years ago

  • Component changed from Date/Time to Database
  • Keywords needs-patch added; 2nd-opinion removed
  • Type changed from defect (bug) to enhancement


#3 @johnjamesjacoby
5 years ago

Somewhat related to #41785...

If there were such a helper function, it could include a MySQL version check, and own the default return value based on that and whatever MySQL modes happen to be set.

This ticket was mentioned in Slack in #core by jjj. View the logs.

4 years ago

This ticket was mentioned in PR #4130 on WordPress/wordpress-develop by @tabrisrp.

16 months ago

  • Keywords has-patch added; needs-patch removed

Add helper functions for default datetime value and check for empty datetime value.

Trac ticket:

Note: See TracTickets for help on using tickets.