|
|
|
แก้รูปแบบวันที่จาก d/m/y เป็น y-m-d ต้องทำอย่างไรบ้างคะ |
|
|
|
|
|
|
|
ไหน ลองเอาโค้ดทั้งหมดมาดูหน่อยครับ
|
|
|
|
|
Date :
2011-10-31 16:23:27 |
By :
yuyu7878 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หั่นเองเลยครับ(ตัดข้อความ)
แล้วค่อยต่อใหม่ตามรูปแบบที่จะเก็บ
มือใหม่ครับ
|
|
|
|
|
Date :
2011-10-31 17:17:52 |
By :
diawcpe |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strtotime ก้ได้ครับ
Code (PHP)
date('Y-m-d', strtotime("30/10/2011"));
|
|
|
|
|
Date :
2011-10-31 20:58:02 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณทุกคนมากค่ะ
|
|
|
|
|
Date :
2011-11-02 23:01:10 |
By :
wanta |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ Function ConvertDate ครับ :)
Code (PHP)
function convertdate($s_date,$s_from,$s_to,$s_return_delimiter) {
$s_return_date = '';
$s_from = strtolower($s_from);
$s_to = strtolower($s_to);
$s_date = str_replace(array('\'', '-', '.', ',', ' '), '/', $s_date);
$a_date = explode('/', $s_date);
switch($s_from) {
case 'eng': # dd/mm/yyyy
$day = $a_date[0];
$month = $a_date[1];
$year = $a_date[2];
break;
case 'usa': # mm/dd/yyyy
$month = $a_date[0];
$day = $a_date[1];
$year = $a_date[2];
break;
case 'iso': # yyyy/mm/dd
$year = $a_date[0];
$month = $a_date[1];
$day = $a_date[2];
break;
default: # error message
user_error('function convertdate(string $s_date, string $s_from, string $s_to, string $s_return_delimiter) $s_from not a valid type of \'eng\', \'usa\' or \'iso\'');
return NULL;
}
# substitution fixes of valid alternative human input e.g. 1/12/08
if (strlen($day)==1) { $day='0'.$day; } # day -trailing zero missing
if (strlen($month)==1) { $month='0'.$month; } # month -trailing zero missing
if (strlen($year)==3) { $year=substr(date('Y'),0,strlen(date('Y'))-3).$year; } # year -millennium missing
if (strlen($year)==2) { $year=substr(date('Y'),0,strlen(date('Y'))-2).$year; } # year -century missing
if (strlen($year)==1) { $year=substr(date('Y'),0,strlen(date('Y'))-1).$year; } # year -decade missing
switch($s_to) {
case 'eng': # dd/mm/yyyy
$s_return_date = $day.$s_return_delimiter.$month.$s_return_delimiter.$year;
break;
case 'usa': # mm/dd/yyyy
$s_return_date = $month.$s_return_delimiter.$day.$s_return_delimiter.$year;
break;
case "iso": # yyyy/mm/dd
$s_return_date = $year.$s_return_delimiter.$month.$s_return_delimiter.$day;
break;
default: # error message
user_error('function convertdate(string $s_date, string $s_from, string $s_to, string $s_return_delimiter) $s_to not a valid type of \'eng\', \'usa\' or \'iso\'');
return NULL;
}
# if it's an invalid calendar date e.g. 40/02/2009 or rt/we/garbage
if (!is_numeric($month) || !is_numeric($day) || !is_numeric($year)) {
return NULL;
} elseif (!checkdate($month, $day, $year)) {
return NULL;
}
return $s_return_date;
}
//echo convertdate('13/04/2009','eng','iso','-');
การใช้งาน ตรวจสอบค่า Input = dd/mm/yyyy หรือไม่
Code (PHP)
$date_reg = '31/12/2011';
list($dd,$mm,$yy)=explode("/",$date_reg);
if(checkdate($mm,$dd,$yy))
{
$Date = convertdate($date_reg,'eng','iso','-');
echo "$Date";
}
|
|
|
|
|
Date :
2011-11-03 17:10:31 |
By :
kamuro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|