|
 |
|
ลบ/เพิ่ม วันเวลาในค่าตัวแปรอย่างไร(รบกวนผู้รู้ช่วยด้วยครับ) |
|
 |
|
|
 |
 |
|
เรื่องมีอยู่ว่า
ดึงค่าวันจาก DB ได้เเสดงบน php 2010-06-07($array[ddate])
ดึงค่าเวลาจาก DB ได้ เเสดงบน php 23:15:00($array[dtime])
เอาค่า2ตัวดังกล่าวมารวมกัน
$newdatetime = $array[ddate]." ".$array[dtime];(echo แล้วได้ค่า2010-06-07 23:15:00)
เสร็จแล้วประกาศค่าให้มันใหม่
$current_shift_datetime= (date("Y-m-d H:i:s", strtotime($newdatetime)));
ต้องการหาเพิม/ลดวันเวลาครับไมรู่ต้องทำอย่างไร
ผมได้ลอง
$current_shift_datetime_out=(date("Y-m-d H:i:s", strtotime("+1 day", $current_shift_datetime)));
$current_shift_datetime_out=(date("Y-m-d H:i:s", strtotime("+1 hour", $current_shift_datetime)));
ค่าที่ได้ยังออกมาผิดครับ
รบกวนผู้รู้ด้วยครับ
**
DB
table time_db
-----------------------------------------------------------------------------------------------------------------------
no. | date(db type 'date') | time_in(db type 'time') | work_hour (db type 'int') |
-----------------------------------------------------------------------------------------------------------------------
1 | 2010-06-27 | 18:50:00 | 8 |
2 | 2010-06-10 | 18:50:00 | 8.30 |
3 | 2010-06-08 | 22:15:00 | 12 |
4 | 2010-06-05 | 03:45:00 | 8 |
-----------------------------------------------------------------------------------------------------------------------
อยากเวลาเลิกงานคือเท่าไร
ผมเลย
$test_date1=2010-06-29 18:00:00;
$test_date2=2010-06-29 ;
sql = "select * from time_db where no='1' "
$date_db = $array_sql[date]." ". $array_sql[time_in];
echo $date_db -------------------------------> ผลที่ได้ 2010-06-29 18:50:00
echo date("Y-m-d ", strtotime("+1 day", array[date]));------------------>ผลที่ได้ 2010-06-29
ecto date("Y-m-d ", strtotime("+1 day", $test_date2));------------------>ผลที่ได้ 2010-06-29
echo date("Y-m-d H:i:s", strtotime("+1 day", strtotime($test_date2)));---------------->ผลที่ได้ 2010-06-29
ecto date("Y-m-d ", strtotime("+1 day", $test_date1));------------------>ผลที่ได้ 1970-01-10 07:00:00 ประมาณนี้ครับ
คือถ้ามีวเวลาด้วยแล้วจะคำวนวผิดเสมอ
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-06-07 13:44:23 |
By :
ziix |
View :
1181 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอไฟล์แบบเต็มๆ ได้ป่าวค่ะ
|
 |
 |
 |
 |
Date :
2010-06-07 14:16:48 |
By :
Kmay |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
up รายละเอียดครับ
|
 |
 |
 |
 |
Date :
2010-06-07 16:55:19 |
By :
ziix |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ประมาณนี้ครับ
<?
$day = new datetime("2010-11-30 12:00:00");
//$daytest =
echo "new date = ".$day->format('Y-m-d H:i:s')."<br>";
$day->modify('next 12 hour');
echo "วันที่/เวลา หลังจากเพิ่ม 5 ชม. = ".$day->format('Y-m-d H:i:s');.
?>
ใครเจอปัญหาอย่างผมลองใช้ดูแล้วกันครับ
credit Khun ProgramMuar จาก web thaiseoboard.com
|
 |
 |
 |
 |
Date :
2010-06-07 22:43:44 |
By :
ziix |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|