Skip to content

Instantly share code, notes, and snippets.

@toshimaru
Created November 6, 2012 09:16
Show Gist options
  • Save toshimaru/4023644 to your computer and use it in GitHub Desktop.
Save toshimaru/4023644 to your computer and use it in GitHub Desktop.
(php) date_parse_from_format
<?php
/**
* convert 20120102 to 2012-1-2
*
* @return string
*/
function convertDate($date) {
$dateInfo = date_parse_from_format('Ymd', $date);
return $dateInfo['year'] . '-' . $dateInfo['month'] . '-' . $dateInfo['day'];
}
// refs. http://www.php.net/manual/en/function.date-parse-from-format.php
php > print_r (date_parse_from_format('Ymd', '20120102'));
Array
(
[year] => 2012
[month] => 1
[day] => 2
[hour] =>
[minute] =>
[second] =>
[fraction] =>
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 0
[errors] => Array
(
)
[is_localtime] =>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment