mysql_to_rfc3339

Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.

Description

(string) mysql_to_rfc3339( (string) $date_string ); 

Explicitly strips timezones, as datetimes are not saved with any timezone information. Including any information on the offset could be misleading.

Returns (string)

Date formatted for ISO8601/RFC3339.

Parameters (1)

0. $date_string (string)
Date string to parse and format.

Usage

  1. if ( !function_exists( 'mysql_to_rfc3339' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Date string to parse and format. 
  5. $date_string = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = mysql_to_rfc3339($date_string); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function mysql_to_rfc3339( $date_string ) { 
  2. $formatted = mysql2date( 'c', $date_string, false ); 
  3.  
  4. // Strip timezone information 
  5. return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );