วันศุกร์ที่ 8 พฤษภาคม พ.ศ. 2552

PHP แปลงข้อมูลจาก String เป็นวันที่ (convert string to datetime)

ใช้เวลาเอาออกมาจาก MySQL ได้ผลดีนักแล เวลาเทียบเวลาใด ๆ โปรดใช้ timestamp นะครับ

MySQL Keep data in DateTime Format but read out in string.
To use that value try to convert to timestamp in PHP
and after on you go.

$str = 'Not Good';

// previous to PHP 5.1.0 you would compare with -1, instead of false
if (($timestamp = strtotime($str)) === false) {
echo
"The string ($str) is bogus";
} else {
echo
"$str == " . date('l dS \o\f F Y h:i:s A', $timestamp);
}
?>

ไม่มีความคิดเห็น: