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. 當爲Date SQL Server字段添加DateTime C#值時,是否應該使用Date或DateTime SqlDbType?
- 5. 從sql date中獲取數據到date
- 6. SQL Server - 將DATETIME的DATE部分添加到DATETIME的TIME部分
- 7. 在sql server中比較date和datetime值date
- 8. 從datetime列提取日期 - SQL Server Compact
- 9. 如何在SQL表中插入varchar(date)到DateTime字段
- 10. 獲取從SQL Server
- 11. 如何從ASP.NET中的SQL Server 2008獲取DateTime對象?
- 12. 僅比較ASP.NET代碼中的DATETIME字段中的DATE
- 13. 從字符串獲取DateTime
- 14. 使用JDBC從Oracle讀取DATE字段
- 15. Python - 在Sql Server Statement中從字段獲取值
- 16. 從SQL Server Reporting Services獲取字段頁面
- 17. 在SQL Server 2005(LDAP)中從Active Directory獲取描述字段
- 18. 從SQL Server獲取字段存儲過程
- 19. Django:獲取字段屬性DateTime值
- 20. SQL Server datetime convert
- 21. 從DATE和TIME創建DATETIME
- 22. 如何從JSP頁面獲取Date字段到repositoryFormHandler?
- 23. 甲骨文 - 獲取從DATE數據類型字段
- 24. 使用EF和SQL Server獲取字段的子字符串
- 25. 如何使用SQL Server獲取max(date)的行記錄?
- 26. 獲取是從SQL Server
- 27. 從sql數據庫獲取datetime
- 28. 如何僅從Sharepoint 2013的DateTime字段獲取日期?
- 29. 如何將NULL插入到SQL Server DATE字段中*來自XML *
- 30. 從列中提取SQL DATE
好的答案是:從WEB_RISK_RISK中選擇creation_date,其中CREATION_DATE = convert(date,GETDATE()) - 感謝提示。 – thegunner 2010-04-13 13:37:41