SQL 将日期/时间减去一个值
我有几列:
| Start | END | Duration
2008-06-28 18.03.55 | 2008-10-06 01.33.55 | End - Start
我的代码如下所示:
SELECT theDelivery,
(char(theDelivery) || ' ' || char(current time)) AS Begin,
(char(theDelivery + 100 DAYS) || ' ' || char(current time + 7 HOURS + 30 MINUTES)) AS End
这是我关于做减法的想法......但它是错误的。我知道你不能减去别名'有什么想法吗? ((char(当前时间 + 7 小时 + 30 分钟) -(char(theDelivery + 100 天)))
所以我发现我的 char 完全错了。我想出了这个,这正是我正在寻找的:
SELECT theDelivery,
TIMESTAMP(theDelivery, current time) AS Begin
,
TIMESTAMP((theDelivery + 100 DAYS), (current time + 7 HOURS + 30 MINUTES)) AS End,
TIMESTAMP((theDelivery + 100 DAYS), (current time + 7 HOURS + 30 MINUTES)) - TIMESTAMP(theDelivery, current time) AS MyDur
I have several columns:
| Start | END | Duration
2008-06-28 18.03.55 | 2008-10-06 01.33.55 | End - Start
My code looks like this:
SELECT theDelivery,
(char(theDelivery) || ' ' || char(current time)) AS Begin,
(char(theDelivery + 100 DAYS) || ' ' || char(current time + 7 HOURS + 30 MINUTES)) AS End
Here is what i thought about doing the subtraction... But its wrong. I know you cant subtract alias' Any thoughts?
((char(current time + 7 HOURS + 30 MINUTES) -(char(theDelivery + 100 DAYS)))
So i figured out i was going all wrong with char's. I came up with this and it was exactly what i was looking for:
SELECT theDelivery,
TIMESTAMP(theDelivery, current time) AS Begin
,
TIMESTAMP((theDelivery + 100 DAYS), (current time + 7 HOURS + 30 MINUTES)) AS End,
TIMESTAMP((theDelivery + 100 DAYS), (current time + 7 HOURS + 30 MINUTES)) - TIMESTAMP(theDelivery, current time) AS MyDur
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您这样做:
((char(current time + 7 HOURS + 30 MINUTES) -(char(theDelivery + 100 DAYS)))
您正在减去字符。您可以尝试:
或者在单行中:
If you do:
((char(current time + 7 HOURS + 30 MINUTES) -(char(theDelivery + 100 DAYS)))
You are substracting chars. You can try:
Or in a sigle line: