BMS-HOSxP Community

HOSxP => HOSxP PCU => ข้อความที่เริ่มโดย: Admin banrai ที่ มิถุนายน 21, 2011, 16:10:32 PM

หัวข้อ: สอบถามวิธีแยก วัน เดือน ปี ให้เป็นภาษาไทยหน่อยครับ
เริ่มหัวข้อโดย: Admin banrai ที่ มิถุนายน 21, 2011, 16:10:32 PM
โค๊ดที่ได้มา ตรง ปี เป็น ค.ศ. ครับ  ผมอยากได้ ปี เป็น พ.ศ. ไม่ทราบว่าทำอย่างไรครับ


select birthdate,left(birthdate,4) as year,
   substr(birthdate,6,2) as month,right(birthdate,2) as date 
   from person limit 100
หัวข้อ: Re: สอบถามวิธีแยก วัน เดือน ปี ให้เป็นภาษาไทยหน่อยครับ
เริ่มหัวข้อโดย: woravet ที่ มิถุนายน 21, 2011, 16:14:43 PM
select birthdate
,year(birthdate)+543 as 'year'
,month(birthdate) as 'month'
,day(birthdate) as 'day'
from person
limit 100
หัวข้อ: Re: สอบถามวิธีแยก วัน เดือน ปี ให้เป็นภาษาไทยหน่อยครับ
เริ่มหัวข้อโดย: woravet ที่ มิถุนายน 21, 2011, 16:32:04 PM
หรือแบบนี้
select birthdate
,year(birthdate)+543 'year'
,case month(birthdate)
when 1 then 'มค.'
when 2 then 'กพ.'
when 3 then 'มีค.'
when 4 then 'เมย.'
when 5 then 'พค.'
when 6 then 'มิย.'
when 7 then 'กค.'
when 8 then 'สค.'
when 9 then 'กย.'
when 10 then 'ตค.'
when 11 then 'พย.'
when 12 then 'ธค.'
else 'ไม่รู้คับ'
end as 'month'
,day(birthdate) as 'day'
from person
limit 100
หัวข้อ: Re: สอบถามวิธีแยก วัน เดือน ปี ให้เป็นภาษาไทยหน่อยครับ
เริ่มหัวข้อโดย: Admin banrai ที่ มิถุนายน 22, 2011, 12:02:47 PM
ขอบคุณครับ