WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 5 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:

Description

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 (2)

#1 @johnjamesjacoby
5 months 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 months ago

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

+1

Note: See TracTickets for help on using tickets.