|
 |
|
ทำไมเวลาแสดงที่หน้าเวป รูปแบบวันที่มันไม่เหมือนที่ Query ใน MSSQL ครับต้องแก้ไขยังไง |
|
 |
|
|
 |
 |
|
ทำไมเวลาแสดงที่หน้าเวป รูปแบบวันที่มันไม่เหมือนที่ Query ใน MSSQL ครับต้องแก้ไขยังไง
Query ใน MSSQL
SELECT createdate,createtime,dateAdd(hour,createTime/100,
DATEADD(minute,createTime % 100,(createDate))) as TDateCreate from oscl t0
ผลที่ได้

แต่ที่หน้าเวปแสดงมันได้ดังนี้ครับ

อยากให้ตรง ตาราง TDateCreate แสดงเหมือนใน Query MSSQL ต้องแก้ยังไงครับมันดันแสดงเป็น Jun 06 2011 01:55:00:000PM แทนที่จะเป็น 2011-06-06 13:55:00.000 ถ้าเป็นไปได้ตัดตรง 00.000 ออกไปให้เหลือแค่ 2011-06-06 13:55 ยิ่งดีครับ
ขอแก้ไขชื่อตารางครับ พอดีหัวตารางชื่อผิดครับ
ช่อง CreateDate คือข้อมูลที่ได้จาก TDateCreate
ช่อง Customer คือข้อมูลที่ได้จาก createdate
ช่อง Address คือข้อมูลที่ได้จาก createtime
รบกวนทุกท่านด้วยนะครับ
ตัด Code คร่าวๆมาให้ดูครับ
Code (PHP)
<html>
<body>
<?
$objConnect = mssql_connect("192.168.1.3\SQL2005","sa","pass") or die("Error Connect to Database");
$objDB = mssql_select_db("db");
$strSQL = "SELECT CONVERT(varchar(10),createDate,103) as createDate,createtime,dateAdd(hour,createTime/100,DATEADD(minute,createTime % 100,(createDate))) as TDateCreate from oscl";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table border="1" align="center" cellspacing="0" bordercolor="#000000" bgcolor="#0033FF">
<tr>
<th width="18"> <div align="center" class="style9 style7">No.</div></th>
<th width="68"> <div align="center" class="style13">CreateDate</div>
<strong>.................</strong></th>
<th width="64"> <div align="center" class="style13">Customer</div>
<strong>................</strong></th>
<th width="60"> <div align="center" class="style13">Address</div>
<strong>...............</strong></th>
</tr>
<?
$i=1;
$j=1;
while($objResult = mssql_fetch_array($objQuery))
{
$j++;
if($j%2==0)
{
$bg = "#99CCFF";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><div align="center" class="style8"><?=$i;?></div></td>
<td><div align="center" class="style8"><?=$objResult["TDateCreate"];?></div></td>
<td align="center"><span class="style8"><?=$objResult["createTime"];?></span></td>
<td><span class="style8"><?=$objResult["custmrName"];?></span></td>
</tr>
<?
$i++;
}
?>
</table>
<?
mssql_close($objConnect);
}
?>
</body>
</html>
Tag : PHP, Ms SQL Server 2005

|
ประวัติการแก้ไข 2012-03-02 01:01:36 2012-03-02 01:07:02 2012-03-02 01:14:48
|
 |
 |
 |
 |
Date :
2012-03-02 00:54:52 |
By :
karurub |
View :
1135 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้การตัดเอาก็ได้ครับ
Code (PHP)
<?php
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 = "2008-08-14 13:42:44";
echo "ThaiCreate.Com Time now : ".DateThai($strDate);
?>
โดยเขียน function ขั้นมาตัวหนึ่งแล้วก็จัดรุปแบบ format ตามต้องการครับ
Go to : PHP Thai Date/Time Function
|
 |
 |
 |
 |
Date :
2012-03-02 06:04:27 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมใช้ CAST + DATEPART จัดการมันให้ออกมาเป็น string ตั้งแต่ตอน select เลย หรือจะเขียนเป็น view ไว้ก็ย่อมได้
|
 |
 |
 |
 |
Date :
2012-03-02 06:11:41 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วปัญหาที่ หน้าเวปแสดงรูปแบบไม่เหมือนที่ใน Query MSSQL นี่คือยังไงครับ
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2012-03-02 08:45:53 |
By :
karurub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนด้วยครับ
|
 |
 |
 |
 |
Date :
2012-03-02 22:17:35 |
By :
karurub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะไปอ่านใน docs หน่อย ประมาณนี้ ปรับเองนะ
Code (PHP)
select cast(datepart(yyyy, fieldname) as varchar(4)) + '/' + cast(datepart(mm, fieldname) as varchar(2)) + '/' + cast(datepart(dd, fieldname) as varchar(2)) + ' ' + cast(datepart(hh, fieldname) as varchar(2)) + ':' + cast(datepart(mi, fieldname) as varchar(2)) as new_date from table
|
 |
 |
 |
 |
Date :
2012-03-02 22:52:03 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|