bp_core_get_iso8601_date

Return an ISO-8601 date from a date string.

Description

(string) bp_core_get_iso8601_date( (string) $timestamp = '' ); 

Returns (string)

Parameters (1)

0. $timestamp — Optional. (string) => ''
String of date to convert. Timezone should be UTC before using this.

Usage

  1. if ( !function_exists( 'bp_core_get_iso8601_date' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // String of date to convert. Timezone should be UTC before using this. 
  5. $timestamp = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_get_iso8601_date($timestamp); 
  9.  

Defined (1)

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

/bp-core/bp-core-functions.php  
  1. function bp_core_get_iso8601_date( $timestamp = '' ) { 
  2. if ( ! $timestamp ) { 
  3. return ''; 
  4.  
  5. try { 
  6. $date = new DateTime( $timestamp, new DateTimeZone( 'UTC' ) ); 
  7.  
  8. // Not a valid date, so return blank string. 
  9. } catch( Exception $e ) { 
  10. return ''; 
  11.  
  12. return $date->format( DateTime::ISO8601 );