|
![](/images/resource/spacer.gif) |
|
MySQL เมื่อผมเล่นกับเวลา เผื่อจะเป็นประโยชน์กับท่านอื่นครับ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
พอดีผมต้องการ query lost time ของ machine ต้องการเวลาเป็น วินาที และ นาที แยก field กัน
กว่าจะคำนวนลงตัวปวดหัวมาก เลยเอามาแบ่งปันครับ ^ ^
Code (PHP)
$sql ="SELECT
IF(TIMESTAMPDIFF(SECOND,time_start,time_end) > 60, //ถ้าเวลามากกว่า 60 วิ
FLOOR(TIMESTAMPDIFF(SECOND,time_start,time_end)/60) //ทำเป็นนาทีโดยไม่เอาเศษ
,'0') ไม่เข้าเงื่อนไขแสดง 0
AS time_error_min,
IF(TIMESTAMPDIFF(SECOND,time_start,time_end) < 60, //ถ้าเวลาน้อยกว่า 60 วิ
TIMESTAMPDIFF(SECOND,time_start,time_end), //แสดงวินาที
TIMESTAMPDIFF(SECOND,time_start,time_end)%60) //ทำเป็นวินาทีโดยเอาเศษเท่านั้นมาคิด
AS time_error_sec
$sql .=" FROM Table";
เพิ่มเติมนะครับ type ของ time_start,time_end เป็น DATETIME
Tag : PHP
![](/images/adv.jpg?v=1001)
|
ประวัติการแก้ไข 2016-09-07 17:04:04
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-09-07 16:57:39 |
By :
thesin18598 |
View :
899 |
Reply :
2 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
![](/images/bbcode/lol.gif?v=1001) ![](/images/bbcode/lol.gif?v=1001)
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-09-08 09:07:20 |
By :
คนมีเสน่ห์ |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
![](/images/bbcode/grin.gif?v=1001)
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-09-08 09:12:01 |
By :
mr.win |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 03
|