Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
In SQL Server 2005 how do I get the current date without the time part? I have been using GETDATE() but would like it to have a time of 00:00:00.
Posted
Comments
Maciej Los 20-Apr-15 5:16am    
SQL Server 2005 or 2008?

Solution 1 by _Canny_Brisk_[^] is very good and recommended to you, if you use SQL Server 2008 and up. In addition to it (just in case you use SQL Server 2005), try this:
SQL
SELECT DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)


Source: Best approach to remove time part of datetime in SQL Server[^]
 
Share this answer
 
v2
Comments
Joezer BH 20-Apr-15 5:19am    
5+2 U 2!

Ha - We've updated the solution for SQL 2005 simultaneously
Maciej Los 20-Apr-15 5:22am    
Thank you ;)
I see it now ;)
Above solution is very good and you can also use this as like an alternate ---




Only for date-

select CONVERT(varchar(10), getdate(), 120)AS coDate1

output-- 2015-04-20



Only for time

select CONVERT(varchar(10), getdate(), 108)AS coTime1

output-- 14:42:35
 
Share this answer
 
v2
You tagged the question SQL-Server-2008R2, in which case use:
SQL
Convert(date, getdate())


BUT, in the question itself you stated SQL Server 2005, in which case, use:
SQL
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))


Cheers,
C
 
Share this answer
 
v2
Comments
Maciej Los 20-Apr-15 5:14am    
+5!
Joezer BH 20-Apr-15 5:17am    
thank you Maciej
Maciej Los 20-Apr-15 5:19am    
You're very welcome. I added my solution. Have you seen it? OP tagged question as SQL Server 2008 R2, but then He's talking about SQL Server 2005.
[EDIT]
Uppsss... I see it now, you have updated your answer. Super!
Here you have clear explanation about date and converting date format
 
Share this answer
 
Comments
Unni R 20-Apr-15 5:18am    
I have one table its contain 3 columns name ,dep and dob . dob data type as "datetime".
select * from empmaster WHERE DOB=getdate().. its not working
Solai Raja 20-Apr-15 5:21am    
Select * From empMaster Where Convert(Date,DOB) = Convert(Date,getdate())
Unni R 20-Apr-15 5:24am    
error mesage "Msg 243, Level 16, State 1, Line 2
Type Date is not a defined system type.
Msg 243, Level 16, State 1, Line 2
Type Date is not a defined system type."
Solai Raja 20-Apr-15 5:33am    
Select * From empMaster Where Convert(Varchar,DOB,101) = Convert(Varchar,getdate(),101)
Unni R 20-Apr-15 5:35am    
Thanku .. its working
SQL
use this . 

select cast(GETDATE() as date)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900