|
 |
|
ถ้าฐานเราบันทึกวันที่เป็น 01/02/2013 แล้วเราต้องการให้แสดงเป็นตัวอักษรทำยังไงคะ |
|
 |
|
|
 |
 |
|
test.php
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php include"date.php";
$aa="01/02/2013";
echo datethai($aa);
?>
date.php
Code (PHP)
<?
function datethai($date){
$thyear = substr($date,6,4);$month = substr($date,3,2);$thday = substr($date,0,2);
if($thday <32 and $thday > 0){
$thday = substr($thday,0,2);
$thday1 = substr($thday,0,1);
$thday2 = substr($thday,1,1);
$thday3 = substr($thday,0,2);
if($thday1==0){ $thday=$thday2;}else{ $thday=$thday3; }
$thMonth = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน",
"กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
/*$thMonth = array("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.",
"ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");*/
$thyear +=543;
$day = $thday." ".$thMonth[$month-1]." ".$thyear;
echo $day ;
}else
{
return $date;
}
}
?>
|
 |
 |
 |
 |
Date :
2013-10-08 11:45:36 |
By :
golfaa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
thaidate.php
<?PHP
function thaistart1($ttt)
{
$d1 = substr($ttt, 0, 2);
$m1 = substr($ttt, 3, 2);
$y = substr($ttt, 6, 4) ;
$y1 = $y-543;
$h1 = substr($ttt, 10, 6);
if ($ttt == "")
{
return "";
} else
{
return $y1 . "-" . $m1 . "-" . $d1;
}
}
function thaistart2($bbb)
{
$d2 = substr($bbb, 8, 2);
$m2 = substr($bbb, 5, 2);
$y3 = substr($bbb, 0, 4) ;
$h2 = substr($bbb, 10, 6);
$y4=$y3+"543";
if($m2=="01"){$m2="มกราคม";}
if($m2=="02"){$m2="กุมภาพันธ์";}
if($m2=="03"){$m2="มีนาคม";}
if($m2=="04"){$m2="เมษายน";}
if($m2=="05"){$m2="พฤษภาคม";}
if($m2=="06"){$m2="มิถุนายน";}
if($m2=="07"){$m2="กรกฎาคม";}
if($m2=="08"){$m2="สิงหาคม";}
if($m2=="09"){$m2="กันยายน";}
if($m2=="10"){$m2="ตุลาคม";}
if($m2=="11"){$m2="พฤศจิกายน";}
if($m2=="12"){$m2="ธันวาคม";}
if ($bbb == "")
{
return "";
} else
{
//return $y1 . "-" . $m1 . "-" . $d1. "" . $h1;
return $d2 . " " . $m2 . " " . $y4;
}
}
function thaistart3($sss)
{
$d3 = substr($sss, 8, 2);
$m3 = substr($sss, 5, 2);
$y3= substr($sss, 0, 4) ;
$y6=$y3+"543";
if ($sss == "")
{
return "";
} else
{
return $d3 . "/" . $m3 . "/" . $y6;
}
}
?>
เวลาเรียกใช้ก็
aaa.php
<?php
include "connectdb.php";
include "thai_date.php";
$sql = "select * from table";
$query = mysql_query($sql ) ;
while($rs= mysql_fetch_array($sql )){
$bbb=$rs['datein'];
$dateshow= thaistart2($bbb);
echo "<TD>";
echo $dateshow;
echo "</TD>";
}
?>
|
 |
 |
 |
 |
Date :
2013-10-08 11:56:06 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|