Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// parse thai style format ex) '05 ก.ย. 2536'
function parse_thai_date($str) {
$thai_months = [
'ม.ค.' => 1,
'ก.พ.' => 2,
'ม.ค.' => 3,
'เม.ย.' => 4,
'พ.ค.' => 5,
'มิ.ย.' => 6,
'ก.ค.' => 7,
'ส.ค.' => 8,
'ก.ย.' => 9,
'ต.ค.' => 10,
'พ.ย.' => 11,
'ธ.ค.' => 12,
];
$parts = explode(' ', $str);
$date = intval($parts[0]);
$month = $thai_months[$parts[1]];
$year = intval($parts[2]) - 543;
return date('Y-m-d', mktime(0, 0, 0, $month, $date, $year));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.