|
 |
|
อันนี้คือหาวัน เวลาได้แล้วแต่เดือนนี่ เอาไปหารอะไรครับ |
|
 |
|
|
 |
 |
|
ลองดูละกันนะ
<?
$mk_data=mktime(1, 0, 0, 2, 1, 2004);
$mk_data2=mktime(1, 0, 0, 3, 1, 2004);
print(gmstrftime("%d",$mk_data2 - $mk_data) - 01);
// ใช้ gmstrftime เพราะว่า จะหาค่าผลต่างเวลาจริง (ไม่งั้น เวลามันจะ +7 hour)
// %S แสดงค่าผลต่างวินาที ( 00 - 59 ) ........ ต้องนำ มา ลบ 0 ก่อนจึงจะได้ผลต่าง (ไม่งั้นเดี๋ยวได้ 00 นะ)
// %M แสดงค่าผลต่างนาที (00 - 59) ........ ต้องนำ มา ลบ 0 ก่อนจึงจะได้ผลต่าง
// %H แสดงค่าผลต่างชั่วโมง (00 - 23) ........ ต้องนำ มา ลบ 0 ก่อนจึงจะได้ผลต่าง
// %d แสดงค่าผลต่างวัน (01 -31) ........ ต้องนำ มา ลบ 1 ก่อนจึงจะได้ผลต่าง (เพราะวันที่เดียวกัน ลบกันต้องได้ 0 ใช่ปะ)
// %m แสดงค่าผลต่างเดือน (01 - 12) ........ ต้องนำ มา ลบ 1 ก่อนจึงจะได้ผลต่าง
// %Y แสดงค่าผลต่างปี (1970 - n) ........ ต้องนำ มา ลบ 1970 ก่อนจึงจะได้ผลต่าง (อีกแล้ว)
//อ้างอิงจาก http://th2.php.net/manual/en/function.strftime.php
// เอา function ไปเลยละกัน เผื่อคนอื่นจะใช้ด้วย
function differentDateTime($mktimeMore, $mktimeLess , $type){
if($type == "s" || $type == "sec" || $type == "second"){
$typeFormat = "%S";
$minusValue = 0;
}else if($type == "M" || $type == "min" || $type == "minute"){
$typeFormat = "%M";
$minusValue = 0;
}else if($type == "h" || $type == "hour"){
$typeFormat = "%H";
$minusValue = 0;
}else if($type == "d" || $type == "day"){
$typeFormat = "%d";
$minusValue = 1;
}else if($type == "m" || $type == "month"){
$typeFormat = "%m";
$minusValue = 1;
}else if($type == "y" || $type == "year"){
$typeFormat = "%Y";
$minusValue = 1970;
}else{
return(false);
}
$different = (gmstrftime($typeFormat , $mktimeMore - $mktimeLess ) - $minusValue );
return($different);
}
$mk_data=mktime(1, 0, 0, 1, 10, 2004);
$mk_data2=mktime(11, 50, 50, 5, 1, 2004);
print("<br><br>".differentDateTime($mk_data2, $mk_data , "sec"));
?>
ได้ไม่ได้ยังไงก็บอกด้วย แต่ผมลองแล้วคิดว่าไม่มีปัญหานะ 
|
 |
 |
 |
 |
Date :
11 ก.ค. 2549 00:52:43 |
By :
Ngokung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
..... คุณ earn นี่ ต้องการคำตอบจริง ๆ ไปโพสคำถามไว้กี่เว็บเนี่ย ที่เจอ ๆ ก็ปาไป 3 แล้วนะ 
|
 |
 |
 |
 |
Date :
11 ก.ค. 2549 01:15:03 |
By :
Ngokung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าอยากคำนวน วดปใ ทำไมไม่เก็บเป็นแบบ vachar ละ ไม่ต้องใช้ฟังชันของ php จะดีกว่ามั้ย
|
 |
 |
 |
 |
Date :
12 ก.ค. 2549 13:55:08 |
By :
โปรแกรมเมอร์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|