How Can I Convert The Standard As400 Cymd Date Format To Mdy In Php?
I am doing quite a few queries within PHP. I am displaying information from these queries but I would like to change the date format to something that people other than programmers
Solution 1:
CYMD The date has the century, year, month, day format, cyymmdd, where c is 0 for years 1928 through 1999 and is 1 for years 2000 through 2071.
Just made it for you: http://ideone.com/6MQmWk
<?phpfunctioncymdToTime($d) {
$matches = null;
preg_match('/^(\\d*)?(\\d\\d)(\\d\\d)(\\d\\d)$/', $d, $matches);
return strtotime( (($matches[1] + 19) * 100 + $matches[2]) . '-' . $matches[3] . '-' . $matches[4]);
}
echo strftime('%B %d, %Y', cymdToTime(960614)); // June 14, 1996echo strftime('%B %d, %Y', cymdToTime(1090225)); // February 25, 2009Solution 2:
A simple UDF can be used to convert CYMD to SQL DATE format on the host:
CREATEFUNCTION QGPL.CYMDTODATE(INDEC(7)) RETURNSDATELANGUAGESQLDETERMINISTICRETURNSNULLONNULL INPUT
BEGINRETURN(DATE(
SUBSTR(DIGITS(19000000+IN),2,4) ||'-'||
SUBSTR(DIGITS(IN),4,2) ||'-'||
SUBSTR(DIGITS(IN),6,2)));
ENDIt can be used like this:
SELECT QGPL.CYMDTODATE(COMPDT) COMPDT
FROM MYLIB.MYTABLE
Post a Comment for "How Can I Convert The Standard As400 Cymd Date Format To Mdy In Php?"