T-SQL将datetime修剪到最近的日期? [英] T-SQL to trim a datetime to the nearest date?

查看:109
本文介绍了T-SQL将datetime修剪到最近的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重复 删除datetime值的时间部分的最佳方法是什么(SQL Server) ?

我有一列可以使用日期时间创建事件的列,但是我想生成一个分组的报告所以我需要一种方法来消除datetime列的时间组件。

I have a column that tracks when things are created using a datetime, but I'd like to generate a report that groups them by day, so I need a way of nulling out the time component of a datetime column.

我该怎么做?

推荐答案

一种方法是将 getdate()更改为列名,

One way is to change getdate() to your column name,

select dateadd(dd, datediff(dd, 0, getdate())+0, 0)

这篇关于T-SQL将datetime修剪到最近的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆