current_time

Retrieve the current time based on specified type.

Description

(int|string) current_time( (string) $type, (int) $gmt = 0 ); 

The mysql type will return the time in the format for MySQL DATETIME field. The timestamp type will return the current timestamp. Other strings will be interpreted as PHP date formats (e.g. Y-m-d,).

If $gmt is set to either 1 or true, then both types will use GMT time. if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.

Returns (int|string)

Integer if $type is 'timestamp', string otherwise.

Parameters (2)

0. $type (string)
Type of time to retrieve. Accepts mysql,, timestamp, or PHP date format string (e.g. Y-m-d).
1. $gmt — Optional. (int)
Whether to use GMT timezone. Default false.

Usage

  1. if ( !function_exists( 'current_time' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date 
  5. // format string (e.g. 'Y-m-d'). 
  6. $type = ''; 
  7.  
  8. // Optional. Whether to use GMT timezone. Default false. 
  9. $gmt = -1; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = current_time($type, $gmt); 
  13.  

Defined (1)

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

/wp-includes/functions.php  
  1. function current_time( $type, $gmt = 0 ) { 
  2. switch ( $type ) { 
  3. case 'mysql': 
  4. return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ); 
  5. case 'timestamp': 
  6. return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 
  7. default: 
  8. return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );