微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQL代码从前一天凌晨4点到当前凌晨3:59提取数据

如何解决SQL代码从前一天凌晨4点到当前凌晨3:59提取数据

我正尝试提取从前一天凌晨4点到当天CST凌晨3:59的前一天的所有数据。

例如: 今天是11/4/20,所以我要从11/3/2020 04:00-11/4/2020 03:59

有人可以帮我吗?我觉得我想得太多了,无法解决

SELECT 
      [auth_account_number] as [Employeee ID],'Pearl Card Withdraw $' as [Time Off],tm.updated_date_time as [Date],[payment_amount] as [Total Time]
  FROM [ig_business].[dbo].[Check_GA_Account_Charge_Detail] cd
  inner join [ig_transaction].[dbo].[Transaction_Master] tm on cd.transaction_data_id=tm.transaction_data_id 

  where tender_dim_id='104'
  and tm.updated_date_time >= convert(datetime,dateadd(day,1,convert(date,getdate()))) + '04:00:00' 
   and tm.updated_date_time < convert(datetime,getdate())) + '04:00:00'

解决方法

假设您有日期/时间列,则可以使用:

select t.*
from t
where dt >= convert(datetime,dateadd(day,-1,convert(date,getdate()))) + '04:00:00' and
      dt < convert(datetime,getdate())) + '04:00:00'
,

我能够弄清楚我使用了这段代码

  and tm.updated_date_time <= dateadd(day,datediff(day,getdate()),0) + '4:00'
  and tm.updated_date_time > dateadd(day,getdate()-1),0) + '4:00'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。