4
A
回答
8
如果您使用SQL Server 2008,现在有一个DATE数据类型。使它更自然!
SELECT CONVERT(Date, GETDATE())
0
这里:
SELECT creation_date
FROM risks
WHERE creation_date = GETDATE()
这将返回存储在risks
表是完全一样的东西是由GETDATE()
函数返回的所有creation_date
值。我假设数据类型creation_date
是Date
。
0
你只需要包括CREATION_DATE在你的SELECT子句是这样的:
select id, creation_date from risks where creation_date = getdate()
+0
尝试它doens't工作....必须转换某处选择creation_date从WEB_RISK_RISK其中CREATION_DATE = GETDATE()。附:有一条是今天被修改的记录。 – thegunner 2010-04-13 13:33:30
1
如果我收到了你的问题的权利,
select convert(varchar, creation_date , 103) as creation_date from tablename
3
它被称为“地板日期时间”,这样做是为了消除时间(这是最快的方法,比使用C更快) ONVERT()或CAST()蜇格式):
DECLARE @datetime datetime;
SET @datetime = '2008-09-17 12:56:53.430';
SELECT DATEADD(day,DATEDIFF(day,0,@datetime),0)
OUTPUT:
-----------------------
2008-09-17 00:00:00.000
(1 row(s) affected)
这里是如何做到这一点的日期时间的其他部分:
--Floor a datetime
DECLARE @datetime datetime;
SET @datetime = '2008-09-17 12:56:53.430';
SELECT '0 None', @datetime -- none 2008-09-17 12:56:53.430
UNION SELECT '1 Second',DATEADD(second,DATEDIFF(second,'2000-01-01',@datetime),'2000-01-01') -- Second: 2008-09-17 12:56:53.000
UNION SELECT '2 Minute',DATEADD(minute,DATEDIFF(minute,0,@datetime),0) -- Minute: 2008-09-17 12:56:00.000
UNION SELECT '3 Hour', DATEADD(hour,DATEDIFF(hour,0,@datetime),0) -- Hour: 2008-09-17 12:00:00.000
UNION SELECT '4 Day', DATEADD(day,DATEDIFF(day,0,@datetime),0) -- Day: 2008-09-17 00:00:00.000
UNION SELECT '5 Month', DATEADD(month,DATEDIFF(month,0,@datetime),0) -- Month: 2008-09-01 00:00:00.000
UNION SELECT '6 Year', DATEADD(year,DATEDIFF(year,0,@datetime),0) -- Year: 2008-01-01 00:00:00.000
ORDER BY 1
PRINT' '
PRINT 'Note that when you are flooring by the second, you will often get an arithmetic overflow if you use 0. So pick a known value that is guaranteed to be lower than the datetime you are attempting to floor'
PRINT 'this always uses a date less than the given date, so there will be no arithmetic overflow'
SELECT '1 Second',DATEADD(second,DATEDIFF(second,DATEADD(day,DATEDIFF(day,0,@datetime),0)-1,@datetime),DATEADD(day,DATEDIFF(day,0,@datetime),0)-1) -- Second: 2008-09-17 12:56:53.000
OUTPUT:
-------- -----------------------
0 None 2008-09-17 12:56:53.430
1 Second 2008-09-17 12:56:53.000
2 Minute 2008-09-17 12:56:00.000
3 Hour 2008-09-17 12:00:00.000
4 Day 2008-09-17 00:00:00.000
5 Month 2008-09-01 00:00:00.000
6 Year 2008-01-01 00:00:00.000
(7 row(s) affected)
Note that when you are flooring by the second, you will often get an arithmetic overflow if you use 0. So pick a known value that is guaranteed to be lower than the datetime you are attempting to floor
this always uses a date less than the given date, so there will be no arithmetic overflow
-------- -----------------------
1 Second 2008-09-17 12:56:53.000
(1 row(s) affected)
0
您可以随时使用月/日/年函数返回它:
declare @date datetime
set @date = '1/1/10 12:00 PM'
select cast(month(@date) as varchar) + '/' + cast(day(@date) as varchar) + '/' + cast(year(@date) as varchar) as theDate
相关问题
- 1. 添加DATE和TIME字段以获取MySQL中的DATETIME字段
- 2. 从sql server获取日期datetime
- 3. 尝试从SQL Server获取XML字段
- 4. 从sql date中获取数据到date
- 5. SQL Server - 将DATETIME的DATE部分添加到DATETIME的TIME部分
- 6. 如何在SQL表中插入varchar(date)到DateTime字段
- 7. 如何从ASP.NET中的SQL Server 2008获取DateTime对象?
- 8. 仅比较ASP.NET代码中的DATETIME字段中的DATE
- 9. 从字符串获取DateTime
- 10. 使用JDBC从Oracle读取DATE字段
- 11. 从SQL Server Reporting Services获取字段页面
- 12. Python - 在Sql Server Statement中从字段获取值
- 13. 在SQL Server 2005(LDAP)中从Active Directory获取描述字段
- 14. 甲骨文 - 获取从DATE数据类型字段
- 15. 从DATE和TIME创建DATETIME
- 16. 使用EF和SQL Server获取字段的子字符串
- 17. 如何使用SQL Server获取max(date)的行记录?
- 18. 从sql数据库获取datetime
- 19. 如何将NULL插入到SQL Server DATE字段中*来自XML *
- 20. 从列中提取SQL DATE
- 21. SQL从XML字段获取数据
- 22. 如何将SQL Server 2005中的DateTime字段增加一个月?
- 23. SQL Server服务器查询 - 计算不同的DateTime字段
- 24. 你怎么存储的DateTimeOffset在SQL Server DateTime字段
- 25. 如何处理来自SQL Server的DBNull DateTime字段?
- 26. 从sql server中的数据字段中提取字符串
- 27. 如何从SQL Server 2014中的一组连接表中获取max(date)?
- 28. 优化加入DATE的SQL查询(datetime)= date?
- 29. 如何查询中获取其中date现在在SQL Server
- 30. 如何比较基于Date和MATEQL的DATETIME字段?
好的答案是:从WEB_RISK_RISK中选择creation_date,其中CREATION_DATE = convert(date,GETDATE()) - 感谢提示。 – thegunner 2010-04-13 13:37:41