|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, November 07, 2012 4:08 PM
Points: 1,525,
Visits: 4,047
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Today @ 1:43 AM
Points: 15,
Visits: 188
|
|
Great handy article !!
However, we can also achieve the same through - SELECT CONVERT(DATETIME,DATEDIFF(dd,0,GETDATE()))
This way we can save the time taken to perform DATEADD operation though it would be quite marginal....
-Vinay Pugalia If a post answers your question, please click "Mark As Answer" on that post. Web : Inkey Solutions Blog : My Blog Email : Vinay Pugalia
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 7:25 AM
Points: 3,
Visits: 123
|
|
the fastest way to remove time from datetime is: select CONVERT(datetime,floor(convert(float,getdate())))
Itzik Ben-Gan had a big post on Date Manipulation with benchmarking..(long time ago..)
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, December 20, 2012 1:03 PM
Points: 265,
Visits: 589
|
|
For some common and uncommon date formats:
http://www.sql-server-helper.com/tips/date-formats.aspx
That site also has code for finding first/last day of month, week, and so on.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 4:31 AM
Points: 344,
Visits: 87
|
|
Hi
I also use CAST(GETDATE() AS date) ... but it works only for sql server 2008 because in an earlier version date is not a type. Another point of view is that a smalldatetime use some bites for storing time even it is 00:00:000. The "date" type is more proper for this case.
____________________________________________________________________ Catalin Dumitru For personal info please visit www.catalin-dumitru.ro
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Monday, April 29, 2013 10:56 AM
Points: 751,
Visits: 129
|
|
Good article, well presented, will probably implement some of it.
Thanks!
Glen Parker
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 1:14 PM
Points: 739,
Visits: 203
|
|
| Another method to strip the time from a date/time value and keep it as a datetime type would be: CONVERT(datetime,CONVERT(varchar,GetDate(),101))
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, April 01, 2013 4:57 PM
Points: 13,
Visits: 178
|
|
| Neat! Will definitely use it.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, September 07, 2012 6:46 AM
Points: 4,
Visits: 25
|
|
On my system using the query for the first day of the week gives Monday instead of Sunday which is, of course, incorrect. Is this based on the locale of the system, or is that consistent behavior all together. After all, the first day of the week is always Sunday not Monday.
SELECT DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)
query performed on 2010-04-07 08:42 query results in 2010-04-05 instead of expected 2010-04-04.
My locale should be en_US.
|
|
|
|