use*_*199 3 postgresql datetime
我有如下表中的数据:
**start_date** **end_date**
--------------- -----------------
2011-06-27 13:24:45.137417 2011-06-28 05:34:26.54939
2011-09-30 09:09:00.501381 2011-10-03 23:38:46.479824
Run Code Online (Sandbox Code Playgroud)
预期结果如下:
Diff
-------
0.16
3.14
Run Code Online (Sandbox Code Playgroud)
小数点前的数字为"天",小数点后的数字为"小时"
我尝试使用extract('epoch'来自(end_date-start_date))/(3600*24)
但它给出格式为100的"小时"值,即第一条记录为0.673395971909722,第二条记录为3.60400438012731
请参阅文档中的格式化功能.
SELECT to_char(end_date - start_date, 'D.HH24') AS diff FROM your_table;
Run Code Online (Sandbox Code Playgroud)
0.16 3.14
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
1661 次 |
| 最近记录: |