แปลงวันที่เป็น 00-00-0000

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา แปลงวันที่เป็น 00-00-0000

แปลงวันที่เป็น 00-00-0000
อยากให้ตรง วันที่ชำระเงินเป็น 00-00-0000 เฉพาะ สถานะกู้ยืมที่ "ยังไม่ได้ชำระเงิน" ค่ะ
<?php require_once('../Connections/connection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_pp = "-1";
if (isset($_POST['word'])) {
  $colname_pp = $_POST['word'];
}
mysql_select_db($database_connection, $connection);
$query_pp = sprintf("SELECT Loans_id, Loans_date, Members_name, Loans_deadline, Loans_status, LP_date, LP_money FROM loans WHERE Members_name LIKE %s", GetSQLValueString("%" . $colname_pp . "%", "text"));
$pp = mysql_query($query_pp, $connection) or die(mysql_error());
$row_pp = mysql_fetch_assoc($pp);
$totalRows_pp = mysql_num_rows($pp);

mysql_select_db($database_connection, $connection);

$query_pp = "SELECT Loans_id, Loans_date, Members_name, Loans_balance, Loans_deadline, Loans_status, LP_date, LP_money FROM loans";

$pp = mysql_query($query_pp, $connection) or die(mysql_error());
$row_pp = mysql_fetch_assoc($pp);
$totalRows_pp = mysql_num_rows($pp);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ศูนย์ข้าวชุมชนตำบลโพกรวม</title>
<style type="text/css">
a:link {
	color: #000;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #000;
}
a:hover {
	text-decoration: none;
	color: #F00;
}
a:active {
	text-decoration: none;
	color: #F00;
}
</style>
</head>
<body background="../img/11 (1).jpg">
<center>
<img src="../img/111.jpg" height="250" width="1024">
<form id="form1" name="form1" method="post" action="payment_show.php">
  <label for="word">ค้นหาชื่อสมาชิก :</label>
  <input type="text" name="word" id="word" />
  <input type="submit" name="button" id="button" value="Submit" />

<table width="1100" border="0" align="center">
  <tr>
    <td align="right"><a href="admin_page.php"><img src="../img/1138515785.gif">  <b>กลับเมนูหลัก</b> <img src="../img/1138515921.gif"></a></td>
  </tr>
</table>
<table border="1" align="center" width="1100">
  <tr align="center">
    <td>รหัสรับชำระเงินกู้ยืม</td>
    <td>วันทำสัญญา</td>
    <td>ชื่อ-สกุลสมาชิก</td>
    <td>ยอดเงินคืน</td>
    <td>กำหนดคืน</td>
    <td>สถานะกู้ยืม</td>
    <td>วันที่ชำระเงิน</td>
    <td>ยอกเงินคืนทั้งหมด</td>
    <td>เพิ่ม</td>
    <td>แก้ไข</td>
    <td>ลบ</td>
    <td>พิมพ์</td>
  </tr>
  <?php do { ?>
    <tr align="center">
      <td><?php echo $row_pp['Loans_id'];?></td>
      <td><?php echo date("d-m-Y",strtotime($row_pp['Loans_date'])); ?></td>
      <td><?php echo $row_pp['Members_name']; ?></td>
      <td><?php echo $row_pp['Loans_balance']; ?></td>
      <td><?php echo date("d-m-Y",strtotime($row_pp['Loans_deadline'])); ?></td>
      <td><?php if(!isset($row_pp['Loans_status']) || $row_pp['Loans_status']=="ยังไม่ได้ชำระเงิน"){  
     echo $row_pp['Loans_status']; 
 } ?></td>
      <td bgcolor="#FF6666"><?php echo date("d-m-Y",strtotime($row_pp['LP_date'])); ?></td>
      <td><?php  echo $row_pp['LP_money']; ?></td>
      <td><a href="payment_insert.php?Loans_id=<?php echo $row_pp['Loans_id']; ?>"><img src="../img/Add.png" width="30" height="28" /></a></td>
      <td><a href="payment_show.php?Loans_id=<?php echo $row_pp['Loans_id']; ?>"><img src="../img/Edit.png" width="30" height="28" /></a></td>
      <td><a href="payment_delete.php?Loans_id=<?php echo $row_pp['Loans_id']; ?>"><img src="../img/delete.png" width="30" height="28" /></a></td>
      <td><div onclick=""><a href="pay_pp.php?Loans_id=<?php echo $row_pp ['Loans_id']; ?>" onclick="{window.open("pay_pp.php?Loans_id=<? echo $row_pp['Loans_id']?>","popup","height=550,width=610,left=200,top=150,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no")}"><img src="../img/printButton.png" width="30" height="28" /></a></td>
    </tr>
    <?php } while ($row_pp = mysql_fetch_assoc($pp)); ?>
</table>
</body>
</center>
</form>
</html>
<?php
mysql_free_result($pp);
?>


Monchusa 125.26.126.xxx 02-01-2016 00:43:31

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1


monchusa 125.26.126.xxx 02-01-2016 00:48
 ความคิดเห็นที่ 2
น่าจะประมาณนี้

<?php if(!isset($row_pp['Loans_status']) || $row_pp['Loans_status']=="ยังไม่ได้ชำระเงิน"){    
     echo "00-00-0000";
 }else{
     echo date("d-m-Y",strtotime($row_pp['LP_date']));
} ?>


ninenik 14.207.53.xxx 06-01-2016
 ความคิดเห็นที่ 3


เมื่อดึงข้อมูลจากฐานข้อมูลแล้วให้แปลงจาก 02-01-2016 เป็น 02 มกราคม 2559 มาแสดงหน้าเว็บ ทำไงคับ


natsaa 183.89.30.xxx 06-05-2016 10:53
 ความคิดเห็นที่ 4
ลองดูการใช้ฟังก์ชั่นต่อไปนี้เป็นแนวทาง

สร้างฟังก์ชั่น แสดงวันที่ ภาษาไทย ด้วย php อย่างง่าย 


ninenik 183.88.76.xxx 06-05-2016
 ความคิดเห็นที่ 5
  ในฐานข้อมูลเป็นแบบนี้

function DateThai($elderBirthday){
$strYear = date("Y",strtotime($elderBirthday))+543;
$strMonth= date("m",strtotime($elderBirthday));
$strDay= date("d",strtotime($elderBirthday));
$strMonthCut=array( "มกรามก","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
 
 
$strMonthThai=$strMonthCut[$strMonth-1];
return "$strDay $strMonthThai $strYear";
}
echo DateThai($rs["elderBirthday"]);

ข้อมูลที่ได้เป็น ไม่ตรงตามฐาน


natsaa 183.89.30.xxx 06-05-2016 15:58
 ความคิดเห็นที่ 6
ต้องแปลงวันที่ให้อยู่ในรูปบบมาตรฐานก่อนคือ 0000-00-00 โดยจัดรูปแบบใหม่
ใช้ปี ค.ศ. 
 
$arrDate = explode("-",$rs["elderBirthday"]); // แยกแล้วเก็บใน array 0 - 1 - 2
//จะได้ $arrDate[0] เป็นวันที่ .. $arrDate[1] เป็นเดือน ..$arrDate[2] เป็นปี ..
//แปลงปีเป็ ค.ศ. ลบด้วย 543 จะได้
$arrDate[2]=$arrDate[2]-543;
$newDate=$arrDate[2]."-".$arrDate[1]."-".$arrDate[0]; // ได้รูปแบบตามต้องการ
echo thai_date_fullmonth(strtotime($newDate));


ninenik 183.88.76.xxx 06-05-2016
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ