Reputation: 33
I am trying to save only date (ex: 2011/09/26 00:00:00
) from getdate()
. I am using sql server 2005.
My sql query is going to be like this:
Insert into Merchant(startdate)
values **today's date only**
How is it possible?
Upvotes: 3
Views: 8222
Reputation: 46067
You can try something like this:
EDIT - Revised to account for rounding after midday.
SELECT CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, GETDATE())))
Here's another apporoach you can try:
SELECT CAST(CONVERT(VARCHAR, GETDATE(), 101) AS DATETIME)
Upvotes: 0
Reputation: 58615
I'm a little late to the party, but here are my 2 cents:
INSERT INTO Merchant
(startdate)
VALUES (cast(GETDATE() as Date))
That, of course, will only work from SQL Server 2008. I'll leave this answer, however, for learning purposes and future references.
Upvotes: 0
Reputation: 12521
select dateadd(dd,0, datediff(dd,0, GETDATE()))
However, if you move to SQL2008, I recommend changing your column to DATE instead of DATETIME.
Upvotes: 0
Reputation: 453628
INSERT INTO Merchant
(startdate)
VALUES (DATEADD(DAY,0,DATEDIFF(DAY,0,GETDATE())))
Upvotes: 4