LoginSignup
1
1

More than 5 years have passed since last update.

Sqlserverで時間の範囲を取得

Posted at

現在時間を含む30分間のデータを取得

e.g.
現在時刻: 09:11
取得範囲: 09:00-09:30

sql
select *
  from 対象テーブル
 where 日時 between
       cast(convert(varchar,dateadd(MINUTE,30-datepart(MINUTE,getdate()),getdate()),0) as DATETIME)
       and
       cast(convert(varchar,dateadd(MINUTE,60-datepart(MINUTE,getdate()),getdate()),0) as DATETIME)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1