select วันที่จากฐานข้อมูล จำนำมาแสดงแบบไทยยังไงครับ
้$strSQL = "SELECT * FROM course WHERE startdate like '%$today%' "
แบบนี้ก็ได้นะครับ กรณี เก็บข้อมูลเป็น DATETIME
Date :
2010-08-03 14:56:17
By :
compeng
ลองเปลี่ยนแล้ว select ไม่ขึ้นครับ
ผมเก็บชนิดข้อมูลเป็น date ครับ
ยังไงก็ขอบคุณมากครับ
ประวัติการแก้ไข 2010-08-03 15:05:59
Date :
2010-08-03 15:02:05
By :
itzone
Code (PHP)
$day="2010-08-03";
$day2=explode('-',$day);
echo $day3=$day2[2].'-'.$day2[1].'-'.$day2[0];
ไทยแบบนี้หรือเปล่าครับ
Date :
2010-08-03 15:09:56
By :
iieszz
ที่ไม่ขึ้น นี้ มันมีข้อมูลวันปัจจุบันไหมครับ หรือว่า ชื่อ ฟิลว์ ผิด
Date :
2010-08-03 15:22:07
By :
compeng
Code (PHP)
<?
function thaidate()
{
$day=array('อาทิตย์','จันทร์','อังคาร','พุธ','พฤหัสบดี','ศุกร์','เสาร์');
$month=array('มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม');
$a=date('w');
$b=date('j');
$c=date('n')-1;
$d=date('Y')+543;
return "วัน<FONT COLOR='#FF00CC'>$day[$a] </FONT>ที่<FONT COLOR='#FF00CC'>$b </FONT>เดือน<FONT COLOR='#FF00CC'>$month[$c] </FONT>พ.ศ.<FONT COLOR='#FF00CC'>$d";
}
echo thaidate();
?>
Date :
2010-08-03 15:48:43
By :
iieszz
Code (PHP)
// Author Tawatchai Wongtom
// http://gunner.freetzi.com
class DateUtil{
const DATE = 1;
const DATETIME = 2;
const TIMESTAMP = 3;
const FULLDATE = 1;
const SHORTDATE = 2;
public $year, $month, $day, $hour, $minute, $second;
private $thai_full_months = array('01'=> 'มกราคม', '02'=> 'กุมภาพันธ์', '03'=> 'มีนาคม', '04'=> 'เมษายน', '05'=> 'พฤษภาคม', '06'=> 'มิถินายน', '07'=> 'กรกฎาคม', '08'=> 'สิงหาคม', '09'=> 'กันยายน', '10'=> 'ตุลาคม', '11'=> 'พฤษจิกายน', '12'=> 'ธันวาคม');
private $thai_short_months = array('01'=> 'ม.ค.', '02'=> 'ก.พ.', '03'=> 'มี.ค.', '04'=> 'เม.ย.', '05'=> 'พ.ค.', '06'=> 'มิ.ย.', '07'=> 'ก.ค.', '08'=> 'ส.ค.', '09'=> 'ก.ย.', '10'=> 'ต.ค.', '11'=> 'พ.ย.', '12'=> 'ธ.ค.');
public function __construct($year, $month, $day, $hour= '00', $minute= '00', $second= '00'){
$this->year = $year;
$this->month = $month;
$this->day = $day;
$this->hour = $hour;
$this->minute = $minute;
$this->second = $second;
}
//create and return DateUtil object, $type will be (date, datetime, timestamp), "now" is ok
//$str parameter format is only "Y-m-d" or "Y/m/d". If you want other format you should use "Constructor" instead.
public static function create($str, $type= self::DATE){
if($str == 'now')
return new DateUtil( date('Y'), date('m'), date('d'), date('H'), date('i'), date('s') );
$hour = '00'; $minute = '00'; $second = '00';
if($type == self::DATE){
list($year, $month, $day) = preg_split('/[-\/]/', $str);
}else if($type == self::DATETIME){
list($date, $time) = preg_split('/\s/', $str);
list($year, $month, $day) = preg_split('/[-\/]/', $date);
list($hour, $minute, $second) = preg_split('/:/', $time);
}else if($type == self::TIMESTAMP){
$timestamp = (int)$str;
$year = date('Y', $timestamp);
$month = date('m', $timestamp);
$day = date('d', $timestamp);
$hour = date('H', $timestamp);
$minute = date('i', $timestamp);
$second = date('s', $timestamp);
}
$month = substr('00'.$month, -2);
$day = substr('00'.$day, -2);
return new DateUtil($year, $month, $day, $hour, $minute, $second);
}// getDateUtil();
//return length between date as day absolute
public function dateDiff(DateUtil $date_compare){
$one_day_timestamp = 24*60*60;
return ceil( ($this->toTimestamp() - $date_compare->toTimestamp()) / $one_day_timestamp );
}
//format Y-m-d
public function toDate(){
return sprintf('%s-%s-%s', $this->year, $this->month, $this->day);
}
//format Y-m-d H:i:s
public function toDateTime(){
return sprintf('%s-%s-%s %s:%s:%s', $this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second);
}
//return int Unix timestamp
public function toTimestamp(){
return mktime((int)$this->hour, (int)$this->minute, (int)$this->second, (int)$this->month, (int)$this->day, (int)$this->year);
}
public function toMySQLDate(){
return addslashes($this->toDate());
}
public function toMySQLDateTime(){
return addslashes($this->toDateTime());
}
public function toMySQLTimestamp(){
return (string)$this->toTimeStamp();
}
//for insert to MySQL database with difference format
public function toMySQLFormat($type= self::DATE){
if($type == self::DATE)
return $this->toMySQLDate();
else if($type == self::DATETIME)
return $this->toMySQLDateTime();
else if($type == self::TIMESTAMP)
return $this->toMySQLTimestamp();
}
//Thai date, format d m Y
public function toThaiDate($type= self::FULLDATE){
$year = $this->year + 543;
$month = ($type == self::FULLDATE) ? $this->thai_full_months[$this->month] : $this->thai_short_months[$this->month];
return sprintf('%d %s %s', $this->day, $month, $year);
}
//Eng date, format Y-m-d
public function toEngDate($type= self::FULLDATE){
$month_format = ($type == self::FULLDATE) ? 'F' : 'M';
$timestamp = mktime(0, 0, 0, (int)$this->month, (int)$this->day, (int)$this->year);
$day = (int)$this->day;
if( $type == self::FULLDATE ){
switch( $day ){
case 1: $numstr = 'st'; break;
case 2: $numstr = 'nd'; break;
case 3: $numstr = 'rd'; break;
default: $numstr = 'th';
}
$day = $day.$numstr;
}
return sprintf('%s %s, %s', date($month_format, $timestamp), $day, $this->year);
}
//return time format H:i:s
public function whatsTime(){
return sprintf('%s:%s:%s', $this->hour, $this->minute, $this->second);
}
//return new DateUtil instance with add Days
public function addDay($day){
$day = (int)$day;
$time_stamp = strtotime('+'.$day.' day', $this->toTimestamp());
return DateUtil::create(date('Y-m-d', $time_stamp));
}
//return the same as DateUtil#toDateTime
public function __toString(){
return $this->toDateTime();
}
}
ตย.
Code (PHP)
$date = DateUtil::create(date('Y-m-d'));
echo $date->toThaiDate(), '<br>';
echo $date->toThaiDate(DataUtil::SHORTDATE);
Date :
2010-08-03 16:59:51
By :
pjgunner
Load balance : Server 02