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
 General SQL Server Forums
 New to SQL Server Programming
 DateTime Format

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2014-12-03 : 07:08:33
Hi,

I have a datetime form I want to convert;

Now the date is 2003-01-01 to replace it to 01/01/2003 I used;

 CONVERT(VARCHAR(10), dbo.EmisPatient.DeathDate, 103)


It worked!!

Now, I have a datetime as 2004-11-04 00:00:00.000

How can I perform the convert to 04/11/2004 00:00:00.000

 CONVERT(VARCHAR(23), dbo.EmisPatient.DeathDate, ?)


Thanks you

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-12-03 : 08:17:24
[code]
DECLARE @var datetime='2004-11-04 00:00:00.000'

Method 1 :

SELECT CONVERT (VARCHAR(10),@var, 101) +' '+ cast(cast(@var AS time) AS varchar(100))

Method 2 :

SELECT replace(convert(varchar, @var, 111), '', '/') +' '+cast(CAST(@var AS time) as varchar(max))
[/code]

---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2014-12-03 : 09:30:46

Both suggestions provide the output as

11/04/2004 00:00:00.0000000



Shouldn't this be

11/04/2004 00:00:00:000
instead.

Thanks

Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-12-03 : 09:43:35
just chop off the extra zeros with a LEFT() function call!
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-12-03 : 09:43:43
just chop off the extra zeros with a LEFT() function call!
Go to Top of Page
   

- Advertisement -