---
title: "获取某时间段的数据"
author: "LvMax"
date: "2011-05-30T20:47:05Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2011-05-30T20:47:05Z"
id: 1065362
url: "https://lvmax.iteye.com/blog/1065362"
---

```sql

declare   @dt   datetime
set   @dt= '2004/08/25 '

--一周內
select   *   from   tb   where   datediff(day,@dt,getdate()) <=7     --@dt相當於日期字段

--一個月內
select   *   from   tb   where   datediff(month,@dt,getdate()) <=1

--半年內
select   *   from   tb   where   datediff(month,@dt,getdate()) <=6 

```