|
 |
|
อยากทราบวิธีแปลง date & time อ่ะค่ะ |
|
 |
|
|
 |
 |
|
อันนี้เป็น function ครับ
Code (PHP)
<?
function Newdate($convD) {
$GGyear=substr($convD,7,4); $GGmonth=substr($convD,2,4); $GGdate=substr($convD,0,2);
if ($GGdate==1) { $GGdatenews="01";
}elseif($GGdate==2) { $GGdatenews="02";
}elseif($GGdate==3) { $GGdatenews="03";
}elseif($GGdate==4) { $GGdatenews="04";
}elseif($GGdate==5) { $GGdatenews="05";
}elseif($GGdate==6) { $GGdatenews="06";
}elseif($GGdate==7) { $GGdatenews="07";
}elseif($GGdate==8) { $GGdatenews="08";
}elseif($GGdate==9) { $GGdatenews="09";
}else{ $GGdatenews=substr($convD,0,2); }
if ($GGmonth=="ม.ค."){ $GGmonthnews="01";
}elseif($GGmonth=="ก.พ."){ $GGmonthnews="02";
}elseif($GGmonth=="มี.ค."){ $GGmonthnews="03";
}elseif($GGmonth=="เม.ย."){ $GGmonthnews="04";
}elseif($GGmonth=="พ.ค."){ $GGmonthnews="05";
}elseif($GGmonth=="มิ.ย."){ $GGmonthnews="06";
}elseif($GGmonth=="ก.ค."){ $GGmonthnews="07";
}elseif($GGmonth=="ส.ด."){ $GGmonthnews="08";
}elseif($GGmonth=="ก.ย."){ $GGmonthnews="09";
}elseif($GGmonth=="ต.ค."){ $GGmonthnews="10";
}elseif($GGmonth=="พ.ย."){ $GGmonthnews="11";
}elseif($GGmonth=="ธ.ค."){ $GGmonthnews="12"; }
$Buffdate=$GGdatenews."/".$GGmonthnews."/".$GGyear;
return $Buffdate;
}
?>
เรียกใช้ก็ Daily_Date=<?=Newdate($objResult["Daily_Date"]);?>
น่าจะได้นะ
|
ประวัติการแก้ไข 2011-06-02 22:16:29
 |
 |
 |
 |
Date :
2011-06-01 17:31:16 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้งานได้เลยค่ะ ขอบคุณมากค่ะ
|
 |
 |
 |
 |
Date :
2011-06-01 17:36:58 |
By :
pumhonda |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก function ติดปัญหาที่เดือนค่ะ
ถ้าเป็นเดือนที่มีตัวอักษร 5 ตัว --> มี.ค. , เม.ย. , มิ.ย.
มันแปลงเดือนออกมาไม่ได้อ่ะค่ะ เช่น 8 เม.ย. 2011 0:00 แปลงออกมาได้เป็นแบบนี้ค่ะ '/08/ 201'
พอไปแก้ เดือนเป็น 5 ตัว $GGmonth=substr($convD,2,5) ยิ่งแปลงเพี้ยนไปใหญ่เลยค่ะ
ทำงัยค่ะ ให้ออกมาเป็น 04/08/2011 อ่ะค่ะ
Code (PHP)
<?
function Newdate($convD) {
$GGyear=substr($convD,7,4); $GGmonth=substr($convD,2,4); $GGdate=substr($convD,0,2);
if ($GGdate==1) { $GGdatenews="01";
}elseif($GGdate==2) { $GGdatenews="02";
}elseif($GGdate==3) { $GGdatenews="03";
}elseif($GGdate==4) { $GGdatenews="04";
}elseif($GGdate==5) { $GGdatenews="05";
}elseif($GGdate==6) { $GGdatenews="06";
}elseif($GGdate==7) { $GGdatenews="07";
}elseif($GGdate==8) { $GGdatenews="08";
}elseif($GGdate==9) { $GGdatenews="09";
}else{ $GGdatenews=substr($convD,0,2); }
if ($GGmonth=="ม.ค."){ $GGmonthnews="01";
}elseif($GGmonth=="ก.พ."){ $GGmonthnews="02";
}elseif($GGmonth=="มี.ค."){ $GGmonthnews="03";
}elseif($GGmonth=="เม.ย."){ $GGmonthnews="04";
}elseif($GGmonth=="พ.ค."){ $GGmonthnews="05";
}elseif($GGmonth=="มิ.ย."){ $GGmonthnews="06";
}elseif($GGmonth=="ก.ค."){ $GGmonthnews="07";
}elseif($GGmonth=="ส.ด."){ $GGmonthnews="08";
}elseif($GGmonth=="ก.ย."){ $GGmonthnews="09";
}elseif($GGmonth=="ต.ค."){ $GGmonthnews="10";
}elseif($GGmonth=="พ.ย."){ $GGmonthnews="11";
}elseif($GGmonth=="ธ.ค."){ $GGmonthnews="12"; }
//$Buffdate=$GGdatenews."/".$GGmonthnews."/".$GGyear;
$Buffdate=$GGmonthnews."/".$GGdatenews."/".$GGyear;
return $Buffdate;
}
?>
|
 |
 |
 |
 |
Date :
2011-06-03 18:43:49 |
By :
pumhonda |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|