note 79033 added to function.strftime
| From: | jerome dot place at free dot fr | Date: | Wed, 07 Nov 2007 20:55:55 +0000 |
| Subject: | note 79033 added to function.strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132088@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) :
# 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));
}
}
}
----
Server IP: 217.174.196.197
Probable Submitter: 82.232.6.118
----
Manual Page -- http://www.php.net/manual/en/function.strftime.php
Edit -- https://master.php.net/note/edit/79033
Del: integrated -- https://master.php.net/note/delete/79033/integrated
Del: useless -- https://master.php.net/note/delete/79033/useless
Del: bad code -- https://master.php.net/note/delete/79033/bad+code
Del: spam -- https://master.php.net/note/delete/79033/spam
Del: non-english -- https://master.php.net/note/delete/79033/non-english
Del: in docs -- https://master.php.net/note/delete/79033/in+docs
Del: other reasons-- https://master.php.net/note/delete/79033
Reject -- https://master.php.net/note/reject/79033
Search -- https://master.php.net/manage/user-notes.php