I have my date values in postdate column in articles table in sql database table. It stores all date as well as time. I would like to get the date part only. i.e from 2010/07/01 12:45:12 i would likfe to get 2010/07/01 in my view
+1
A:
you can use either of the two
select substring(getdate(),0,10)
use
select convert(varchar,getdate(),111)
Shantanu Gupta
2010-07-22 05:22:05
+6
A:
With SQL Server 2008, you can cast the value as DATE. With previous versions, you can use a trick over DATEADD:
DECLARE @d DATETIME;
SELECT @d = '2010-07-22 12:45:22';
-- all versions of sql server
SELECT DATEADD(DAY, DATEDIFF(DAY, 0, @d), 0);
-- sql server 2008
SELECT CAST(@d AS DATE);
Greets Flo
Florian Reischl
2010-07-22 05:24:03
amazing, I never knew about that DATEADD trick before! I was always converting to/from a char(10) to 'fake it'.
Coxy
2010-07-22 05:35:15
Thanks :-)! I've learned that on SCC. Since then, I've already used it hundred times.
Florian Reischl
2010-07-22 05:40:25
thnx gr8 trick it worked
KoolKabin
2010-07-22 07:00:01