Created
November 6, 2012 09:16
-
-
Save toshimaru/4023644 to your computer and use it in GitHub Desktop.
(php) date_parse_from_format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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