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)
 Trucate seconds in date

Author  Topic 

kiran
Starting Member

30 Posts

Posted - 2004-06-30 : 17:50:04
I need help in sql query in truncating seconds in datetime column that is

6/30/2004 1:13:53 PM should be display as 6/30/2004 1:13 PM

thanks in advance...


derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-30 : 18:09:26
Pick one:

SET NOCOUNT ON

DECLARE
@min INT,
@max INT,
@date DATETIME

SELECT
@min = 1,
@max = 131,
@date = GETDATE()

SELECT @date

WHILE @min <= @max
BEGIN

IF @min BETWEEN 15 AND 19
OR @min = 26
OR @min BETWEEN 27 AND 99
OR @min BETWEEN 115 AND 119
OR @min BETWEEN 122 AND 125
OR @min BETWEEN 127 AND 129
BEGIN
GOTO NEXT_LOOP
END

SELECT @min, CONVERT(VARCHAR,@date,@min)

NEXT_LOOP:

SELECT @min = @min + 1
END

If you don't like any of these, get what you want with DATEPART and concatenation.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-06-30 : 22:09:10
Another option:
select convert(varchar,getdate())
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-06-30 : 23:44:46
SELECT DATEADD(Minute, DATEDIFF(Minute, 0, getdate()), 0)
Go to Top of Page
   

- Advertisement -