如何从getdate()永久获取大日期到90天?

时间:2017-09-12 16:50:44

标签: sql sql-server

我想通过拍摄当天的日期在90天前保留日期。 Tablonun ismi:etl.PackageExecutionDuration 我希望将记录删除90天。要比较的列名:created_time。在90天之前它将是23:59:59。 我怎么能这样做?

我已完成以下查询,但有更简单的方法或形状?

DELETE etl.PackageExecutionDuration where created_time<   (select CONVERT(datetime,
  DATEADD(SECOND,-1,
  CONVERT(datetime,
  CONVERT(date, 
  CONVERT(datetime, 
  DATEADD(DAY, -89, GETDATE())))))))

3 个答案:

答案 0 :(得分:1)

简化为:

where created_time <= cast(dateadd(day, -90, getdate()) as date)

答案 1 :(得分:0)

DELETE etl.PackageExecutionDuration where created_time<   (select CONVERT(datetime,
  DATEADD(milisecond,-1,
  CONVERT(datetime,
  CONVERT(date, 
  CONVERT(datetime, 
  DATEADD(DAY, -89, GETDATE())))))))

答案 2 :(得分:0)

DELETE etl.PackageExecutionDuration where created_time<   (select CONVERT(datetime,
  DATEADD(SECOND,-1,
  CONVERT(datetime, 
  DATEADD(DAY, -11, GETDATE())))))

此True查询