Make WordPress Core

Opened 3 years ago

Last modified 15 months ago

#46210 new enhancement

Add helpers for default/empty datetime value

Reported by: johnjamesjacoby Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Database Keywords: needs-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 (4)

#1 @johnjamesjacoby
3 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
3 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
2 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.

15 months ago

Note: See TracTickets for help on using tickets.