HTML
★ php substr ★ PHP 시간처리 (MySQL, time, substr, mktime)
아이맥스
2011. 5. 10. 09:31
// MySQL 에서 현재시간 가져옴
$sql_query = "select now()";
$res = $db->query($sql_query);
$data = $db->fetch_array($res);
// $now = time();
$YY = (int)substr($data[0], 0, 4);
$MM = (int)substr($data[0], 5, 2);
$DD = (int)substr($data[0], 8, 2);
$HH = (int)substr($data[0], 11, 2);
$MI = (int)substr($data[0], 14, 2);
$tm_unix_now = mktime($HH,$MI,0,$MM,$DD,$YY);
$tm_unix_pre = $tm_unix_now - 5*60; // 5분전 시간
$tm_now = date('YmdHi', $tm_unix_now);
$tm_pre = date('YmdHi', $tm_unix_pre);
echo "tm_now : $tm_now <br>";
echo "tm_pre : $tm_pre <br>";