|
 |
|
อยากทราบว่าถ้าเราเก็บในฐานข้อมูลเป็น 12/01/2011 เราจะแปลอย่างไรให้แสดงเป็นวันจันทร์ ที่ 12 เดือนมกราคม 2554 ค่ะ |
|
 |
|
|
 |
 |
|
ใช้การแยกค่าวัน เดือน ปี ออกมาก่อนครับ ใช้ฟังก์ชั่น explode ก็ได้ แล้วนำค่าทีได้ไปเปรียบเทียบแต่ล่ะส่วน เช่น ลำดับของเดือนก็แทนด้วยชื่อเดือน ปีก็บวก 543 เข้าไปเพื่อให้เป็น พ.ศ.
ตัวอย่าง
Code (PHP)
<?php
$date_time = "12/01/2011";
$date_explode = explode("/", $date_time);
$month_thai = array('', 'มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม');
$return_date = $date_explode[0]." เดือน".$month_thai[intval($date_explode[1])]." ".($date_explode[2] + 543);
echo $return_date;
?>
|
ประวัติการแก้ไข 2011-01-31 22:48:29
 |
 |
 |
 |
Date :
2011-01-31 22:48:06 |
By :
zankumuro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะแล้วพวกวันทำไงค่ะ
|
 |
 |
 |
 |
Date :
2011-02-01 15:57:57 |
By :
deedee2338 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เงียบเลย
|
 |
 |
 |
 |
Date :
2011-02-01 21:10:14 |
By :
deedee2338 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
function fullthaidate($input_date) {
$array_dayofweek = array('อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์');
$array_thaimonth = array(1 => 'มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม');
list($dd, $mm, $yy) = explode("/", $input_date);
$time = mktime(0, 0, 0, $mm, $dd, $yy);
return "วัน" . $array_dayofweek[date("w", $time)] . ' ที่ ' . date("j", $time) . ' เดือน' . $array_thaimonth[date("n", $time)] . ' ' . (date("Y", $time) + 543);
}
print fullthaidate("12/01/2011");
ลองเอาไปประยุกต์ดูนะคะ
|
 |
 |
 |
 |
Date :
2011-02-01 21:27:43 |
By :
Rei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2011-02-06 21:22:29 |
By :
deedee2338 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|