mysql2date

Definition:
function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {}

Converts MySQL DATETIME field to user specified date format.
If $dateformatstring has ‘G’ value, then gmmktime() function will be used to make the time. If $dateformatstring is set to ‘U’, then mktime() function will be used to make the time.

Parameters

  • string $dateformatstring: Either ‘G’, ‘U’, or php date format.
  • string $mysqlstring: Time from mysql DATETIME field.
  • bool $translate: Optional. Default is true. Will switch format to locale.

Return values

returns:Date formatted by $dateformatstring or locale (if available).

Source code

function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {

	$m = $mysqlstring;

	if ( empty( $m ) )

		return false;



	if ( 'G' == $dateformatstring )

		return strtotime( $m . ' +0000' );



	$i = strtotime( $m );



	if ( 'U' == $dateformatstring )

		return $i;



	if ( $translate )

		return date_i18n( $dateformatstring, $i );

	else

		return date( $dateformatstring, $i );

}

2419

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: