Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > อยากทราบวิธีแปลง date & time อ่ะค่ะ



 

อยากทราบวิธีแปลง date & time อ่ะค่ะ

 



Topic : 061047



โพสกระทู้ ( 260 )
บทความ ( 0 )



สถานะออฟไลน์




ใช้ datepicker ในการ select date ซึ่งตั้งเป็น mdy (แทนค่าด้วย d1 และ d2)
date จาก datepicker ส่งออกมาเป็น 01/01/2011
แล้วฟอร์มที่ใช้รับ connect กับ sql server2000 ในฐาน date ของ sql server ถ้าเป็นวันที่ 1 มค 2011 แสดงเป็น 01/Jan/2011

แต่ตอนที่เรา select ให้มาแสดงในหน้าเวปของเรา มันแสดงเป็น 1 ม.ค. 2011 0:00
ทีนี้ตอนที่ทำให้มัน link ไปอีกหน้า เราให้ link ด้วย date เลยส่งไปเป็น 1 ม.ค. 2011 0:00
หน้าที่ link ไปเลย error แบบนี้เลยค่ะ

Warning: mssql_query(): message: Syntax error converting datetime from character string. (severity 16) in d:\appserv\www\...

มีวิธีแปลง date จาก 1 ม.ค. 2011 0:00 ให้เป้น 01/01/2011 มั้ยค่ะ
จะเอาไปใช้ที่หน้าที่ link ด้วย date อ่ะค่ะ จะได้ส่ง date ไปเป็น 01/01/2011 ค่ะ
ตรงที่ &Daily_Date=<?=$objResult["Daily_Date"]?>

code

WHERE Dept1='$l_code' and Dept2='$l_code' and Daily_Date between '$d1' and '$d2'

code ที่ให้ link ไปอีกหน้า
<a href="detail2.php?l_code=<?=$res1["l_code"]?>&Daily_Date=<?=$objResult["Daily_Date"]?>" target="_blank"><img src="img/detail.gif" border="0"></a>



Tag : PHP, MySQL









ประวัติการแก้ไข
2011-06-01 16:47:14
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-06-01 16:45:15 By : pumhonda View : 925 Reply : 3
 

 

No. 1



โพสกระทู้ ( 616 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Facebook

อันนี้เป็น 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
 


 

No. 2



โพสกระทู้ ( 260 )
บทความ ( 0 )



สถานะออฟไลน์


ใช้งานได้เลยค่ะ ขอบคุณมากค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-01 17:36:58 By : pumhonda
 

 

No. 3



โพสกระทู้ ( 260 )
บทความ ( 0 )



สถานะออฟไลน์


จาก 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
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากทราบวิธีแปลง date & time อ่ะค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่