 |
ผมต้องการแปลงเวลาเป็นไทยครับ ซึ่งได้ลองทำแล้วก็ยังไม่ได้ค่าที่ต้องการ |
|
 |
|
|
 |
 |
|
code ที่จะแสดงผลในหน้าหลักครับ ซึ่งผมจะแปลงค่า $row["ad_time_bank"];
ซึ่งวันที่ที่ได้นั้นถูกต้องแต่เวลาหายไป 7ชั่วโมง
Code (PHP)
$sql = "SELECT * FROM `bank_note` JOIN u_admin ON u_admin.id_u_admin=bank_note.id_u_admin JOIN bank_owner on bank_owner.id_ow=bank_note.id_ow JOIN type_bank on type_bank.id_type_b=bank_owner.id_type_b ";
if( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
$sql.=" AND ( DATE_FORMAT(ad_time_bank, '%Y-%m-%d') like '".$requestData['search']['value']."%' ";
$sql.=" OR user_admin LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR name_type_b LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR b_ow LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR money_ad LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR note LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees 2");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY `bank_note`.`ad_time_bank` DESC LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees 3");
$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = $row["ad_time_bank"];
$nestedData[] = $row["user_admin"];
$nestedData[] = $row["name_type_b"];
$nestedData[] = $row["b_ow"];
$nestedData[] = $row["money_ad"];
$nestedData[] = $row["note"];
$data[] = $nestedData;
}
________________________________________________________________
ที่ลองแปลงเมื่อค่าที่ออกมามีค่า2 แถวขึ้นไปก้อไม่สามารถแสดงค่าได้ แต่ตอนที่แสดงได้ วันที่ถูกแต่ชั่วโมงหายไป 7ชั่วโมงคับ
Code (PHP)
$sql = "SELECT * FROM `bank_note` JOIN u_admin ON u_admin.id_u_admin=bank_note.id_u_admin JOIN bank_owner on bank_owner.id_ow=bank_note.id_ow JOIN type_bank on type_bank.id_type_b=bank_owner.id_type_b ";
if( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
$sql.=" AND ( DATE_FORMAT(ad_time_bank, '%Y-%m-%d') like '".$requestData['search']['value']."%' ";
$sql.=" OR user_admin LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR name_type_b LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR b_ow LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR money_ad LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR note LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees 2");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY `bank_note`.`ad_time_bank` DESC LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees 3");
$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strHour= date("H",strtotime($strDate));
$strMinute= date("i",strtotime($strDate));
$strSeconds= date("s",strtotime($strDate));
$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear, $strHour:$strMinute";
}
$strDate = $row["ad_time_bank"];
$date = DateThai($strDate);
$nestedData[] = $date;
$nestedData[] = $row["user_admin"];
$nestedData[] = $row["name_type_b"];
$nestedData[] = $row["b_ow"];
$nestedData[] = $row["money_ad"];
$nestedData[] = $row["note"];
$data[] = $nestedData;
}
Tag : PHP, Ajax, jQuery
|
|
 |
 |
 |
 |
Date :
2016-11-25 10:20:01 |
By :
darknight |
View :
885 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองไปศึกษาเพิ่ม เรื่อง function ดูนะ น่าจะประมาณนี้
Code (PHP)
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = DateThai( $row["ad_time_bank"]);
$nestedData[] = $row["user_admin"];
$nestedData[] = $row["name_type_b"];
$nestedData[] = $row["b_ow"];
$nestedData[] = $row["money_ad"];
$nestedData[] = $row["note"];
$data[] = $nestedData;
}
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strHour= date("H",strtotime($strDate));
$strMinute= date("i",strtotime($strDate));
$strSeconds= date("s",strtotime($strDate));
$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear, $strHour:$strMinute";
}
|
ประวัติการแก้ไข 2016-11-25 11:04:09
 |
 |
 |
 |
Date :
2016-11-25 11:03:22 |
By :
thesin18598 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ฮ่าๆๆ อ่านคำถามผิด ^^"
Code (PHP)
$th_mon = array(
"01" => 'มกราคม',
"02" => 'กุมภาพันธ์',
"03" => 'มีนาคม',
"04" => 'เมษายน',
"05" => 'พฤษภาคม',
"06" => 'มิถุนายน',
"07" => 'กรกฎาคม',
"08" => 'สิงหาคม',
"09" => 'กันยายน',
"10" => 'ตุลาคม',
"11" => 'พฤศจิกายน',
"12" => 'ธันวาคม'
);
$date = $row['ad_time_bank'];
$time = end(explode(' ', $row['ad_time_bank']));
$year = substr($date, 0, 4) + 543;
$month = $th_mon[substr($date, 5, 2)];
$day = substr($date, 8, 2);
return $day . " " . $month . " " . $year . ", " . $time;
-----------------------------------------------------------------
Code (PHP)
echo date( "Y-m-d", strtotime( "$row[ad_time_bank] +7 hours" ) );
http://php.net/manual/en/function.strtotime.php
ถ้าโค้ด SQL จะประมาณนี้ครับ
Code (SQL)
SELECT ADDTIME( ad_time_bank, '7:00:00' )
http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_addtime
|
ประวัติการแก้ไข 2016-11-25 13:59:39
 |
 |
 |
 |
Date :
2016-11-25 13:50:24 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Array เหมือนกัน
function DateThai($strDate = '') {
$strYear = date("Y", strtotime($strDate)) + 543;
$strMonth = date("n", strtotime($strDate));
$strDay = date("j", strtotime($strDate));
$strHour = date("H", strtotime($strDate));
$strMinute = date("i", strtotime($strDate));
$strSeconds = date("s", strtotime($strDate));
$strMonthCut = Array("", "มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม");
$strMonthThai = $strMonthCut[$strMonth];
return " วันที่ $strDay เดือน $strMonthThai พ.ศ. $strYear ";
}
$strDate = date("Y-m-d");
echo DateThai($strDate);
|
 |
 |
 |
 |
Date :
2016-11-25 14:32:50 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|