note 79033 modified in function.strftime by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 03:46:27 +0000 |
| Subject: | note 79033 modified in function.strftime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142086@lists.php.net to get a copy of this message | ||
Here is a function to convert dates before 1970, very useful if you are still using php 4 (it is
supported in php5) :
<?php
# convert a date to special format
# $date is like 2000-01-01 00:00:00
# $format : refer to strftime function
function convert_date($date,$format) {
if($date=='0000-00-00 00:00:00' OR $date=='0000-00-00' OR $date==''
OR $date==NULL) {
return '';
}
else {
$year=substr($date,0,4);
if(phpversion() < 5.0 AND $year < 1970) {
$new_date=substr_replace($date,'1980',0,4); # we replace the year by a year after
1970
$new_format=eregi_replace('%a|%A|%u','',$format); # we remove days
information from the format because they would be wrong
$new_date=strftime($new_format,strtotime($new_date)); # we convert the date
$new_date=eregi_replace('1980',$year,$new_date); # we put back the real year
return $new_date;
}
else {
return strftime($format,strtotime($date));
}
}
}
?>
--was--
Here is a function to convert dates before 1970, very useful if you are still using php 4 (it is
supported in php5) :
# convert a date to special format
# $date is like 2000-01-01 00:00:00
# $format : refer to strftime function
function convert_date($date,$format) {
if($date=='0000-00-00 00:00:00' OR $date=='0000-00-00' OR $date==''
OR $date==NULL) {
return '';
}
else {
$year=substr($date,0,4);
if(phpversion() < 5.0 AND $year < 1970) {
$new_date=substr_replace($date,'1980',0,4); # we replace the year by a year after
1970
$new_format=eregi_replace('%a|%A|%u','',$format); # we remove days
information from the format because they would be wrong
$new_date=strftime($new_format,strtotime($new_date)); # we convert the date
$new_date=eregi_replace('1980',$year,$new_date); # we put back the real year
return $new_date;
}
else {
return strftime($format,strtotime($date));
}
}
}
http://php.net/manual/en/function.strftime.php