|  | 
	                
  
    | 
	 
        ทำอย่างไรให้เก็บวันที่ในรูปแบบ dd/mm/yy ลงฐานข้อมูลได้ครับ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | ทำอย่างไรให้เก็บวันที่ในรูปแบบ dd/mm/yy ลงฐานข้อมูลได้ครับ ถ้าผมเปลี่ยนจาก dd/mm/yy เป็น yy/mm/dd ก็จะทำให้บันทึกลงฐานข้อมูลได้
 แต่ txtbox ที่ 3 มันจะรวมจำนวนวันออกมาผิดอ่าครับ พอมีแนวทางบ้างไหมครับ
 
 
 Code (PHP)
 
 <?php require_once('Connections/LeaveCP.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;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO record (Date_start, Date_end, Rec_Day) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['start_date'], "date"),
                       GetSQLValueString($_POST['end_date'], "date"),
                       GetSQLValueString($_POST['sumDay'], "int"));
  mysql_select_db($database_LeaveCP, $LeaveCP);
  $Result1 = mysql_query($insertSQL, $LeaveCP) or die(mysql_error());
}
?>
<!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>Untitled Document</title>
<link rel="stylesheet" media="all" type="text/css" href="js/jquery-ui.css" />
<link rel="stylesheet" media="all" type="text/css" href="js/jquery-ui-timepicker-addon.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="js/jquery-ui-sliderAccess.js"></script>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <p>
    Start Date : <input type="text" name="start_date" id="start_date" value="" /> 
    <br />
    <br />
    End Date :
<input type="text" name="end_date" id="end_date" value="" />
    <br />
    <br />
    รวมจำนวนวัน  : <input name="sumDay" type="text" id="sumDay" value="0" size="5" maxlength="2" />
    
<script type="text/javascript">
/* create an array of days which need to be disabled */
var disabledDays = "";
/* utility functions */
function nationalDays(start_date) {
	var m = start_date.getMonth(), d = start_date.getDate(), y = start_date.getFullYear();
	//console.log('Checking (raw): ' + m + '-' + d + '-' + y);
	for (i = 0; i < disabledDays.length; i++) {
		if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1 || new Date() > start_date) {
			//console.log('bad:  ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
			return [false];
		}
	}
	//console.log('good:  ' + (m+1) + '-' + d + '-' + y);
	return [true];
}
function noWeekendsOrHolidays(start_date) {
	var noWeekend = jQuery.datepicker.noWeekends(start_date);
	return noWeekend[0] ? nationalDays(start_date) : noWeekend;
}
/* utility functions */
function nationalDays(end_date) {
	var m = end_date.getMonth(), d = end_date.getDate(), y = end_date.getFullYear();
	//console.log('Checking (raw): ' + m + '-' + d + '-' + y);
	for (i = 0; i < disabledDays.length; i++) {
		if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1 || new Date() > end_date) {
			//console.log('bad:  ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
			return [false];
		}
	}
	//console.log('good:  ' + (m+1) + '-' + d + '-' + y);
	return [true];
}
function noWeekendsOrHolidays(end_date) {
	var noWeekend = jQuery.datepicker.noWeekends(end_date);
	return noWeekend[0] ? nationalDays(end_date) : noWeekend;
}
/* create datepicker */
jQuery(document).ready(function() {
	jQuery('#start_date').datepicker({
		//minDate: new Date(2010, 0, 1),
		//maxDate: new Date(2010, 5, 31),
		//dateFormat: 'DD, MM, d, yy',
		showOn: "button",
		buttonImage: "image/formcal.gif",
		buttonImageOnly: true,
		dateFormat: 'dd/mm/yy',
		constrainInput: true,
		//beforeShowDay: noWeekendsOrHolidays
	});
$("#end_date").datepicker({
				showOn: "button",
				buttonImage: "image/formcal.gif",
				buttonImageOnly: true,
                //minDate: +3,
				constrainInput: true,
				// beforeShowDay: noWeekendsOrHolidays,
				dateFormat: 'dd/mm/yy',
				onSelect: function (dateText, inst) {
                    var date2 = dateText;
                    var date1 = $("#start_date").val();
                    date1 = date1.split("/");
                    date2 = date2.split("/");
                    sDate = new Date(date1[2], date1[1] - 1, date1[0]);
                    eDate = new Date(date2[2], date2[1] - 1, date2[0]);
					
					//alert(jQuery('#sDate').val());
					//alert(jQuery('#eDate').val());
                    var daysDiff = Math.round(((eDate - sDate) / 86400000)+1); //totalday + 1//
					//var daysDiff = Math.round((eDate - sDate) / 86400000);
                    $("#sumDay").val(daysDiff.toString());
                    var result = parseInt($("#day_old").val()) + parseInt($("#sumDay").val());
                    $("#txtAns").val(result);
                }
            });
});
</script>
    
  </p>
  <p>
    <input type="submit" name="button" id="button" value="Submit" />
    <br />
  </p>
  <p> </p>
  <p> </p>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
 
 
 Tag : PHP
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2015-04-26 00:28:36 | By :
                          saovarott159 | View :
                          960 | Reply :
                          5 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ต.ย. ประยุกต์เอาครับ 
 function thai3($ttt)
	{
		$d1 = substr($ttt, 0, 2);
		$m1 = substr($ttt, 3, 2);
		$y = substr($ttt, 6, 4) ;
		if ($ttt == "")
		{
			return "";
		} else
		{
			return $y . "-" . $m1 . "-" . $d1;
		}
	}
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-04-26 07:57:17 | By :
                            apisitp |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เดี่ยวขอลองดูก่อนนะครับ 
 |  
              | 
 ประวัติการแก้ไข
 2015-04-26 15:33:51
 2015-04-27 11:08:42
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-04-26 14:50:16 | By :
                            saovarott159 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ก่อนอื่น บันทัดที่ 83 - 118 
 แก้ให้เหลือ function ละอันพอครับ ฟังก์ชันเหมือน กันเลย
 
 
 จากคห 2 เอา ฟังก์ชั่น thai3() ไปใช้ตรงไหนครับ
 และเอา function thai3($ttt){ .... } ไปอยู่ต้นไฟล์เลยครับ ไม่ต้องเอามาอยู่ใน <html>
 เป็น ฟังก์ชันของ PHP
 
 
 คำสั่งทดสอบ function thai3
 <?=thai3('31/12/2015')?>
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-04-26 16:21:13 | By :
                            Chaidhanan |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบคุณพี่ๆมากๆครับ 
 |  
              | 
 ประวัติการแก้ไข
 2015-04-27 11:07:56
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-04-26 19:45:25 | By :
                            saovarott159 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 |  |