Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 datetime

Author  Topic 

noamg
Posting Yak Master

215 Posts

Posted - 2005-01-06 : 07:08:35
I have a column that hold string, like: '2004-11-23 09:54:24.000'.
how to get the date only, without time ?



Noam Graizer

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2005-01-06 : 07:37:15
SELECT DATEADD(d,DATEDIFF(d,0,getdate()),0)
SELECT CONVERT(DATETIME,CONVERT(CHAR(8),GETDATE(),112))
SELECT CONVERT(CHAR(8),GETDATE(),112)

SELECT CAST(CAST(GETDATE() AS VARCHAR(12)) AS DATETIME)
SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)

SELECT CAST(SUBSTRING(CAST(GETDATE() AS BINARY(8)),1,4) + 0x00000000 AS DATETIME)
SELECT CAST(CAST(SUBSTRING(CAST(GETDATE() AS binary(8)),1,4) AS INT) AS DATETIME)

--
Frank
http://www.insidesql.de
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-06 : 08:24:34
haven't seen anyone covert it to binary before...

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2005-01-06 : 10:15:12
If you consider how a DATETIME is stored internally, this is probably one of the fastest method to set the time to midnight.

--
Frank
http://www.insidesql.de
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-06 : 10:27:08
it's stored as 2 integers. so i doubt that substring-ing it is fastest.
i'd probably stick to dateadd...

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2005-01-07 : 06:43:21
No, it is stored as BINARY(8)! But you're right it contains two INTEGER's
Anyway, I also use DATEADD. It's more readable and understandable to me.

--
Frank
http://www.insidesql.de
Go to Top of Page
   

- Advertisement -