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 2005 Forums
 Transact-SQL (2005)
 date format

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2007-06-25 : 07:20:39
how to convert the below dateformat to '1978-05-12'

DEclare @tmp varchar(100)
DEclare @test varchar(10)
set @tmp='12/05/1978'
select @test=convert(char(10),@tmp,102)
print @test

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-25 : 07:33:36
convert(datetime, @tmp, 121)

--------------------------------------------------
S.Ahamed
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-25 : 08:00:29
1. conversion formats in CONVERT() function apply only while converting from date to character data.
2. Storing dates as character data is bad design
3. You can easily accomplish this from the front-end.
4. Here is one working solution:

Set Dateformat DMY

Declare @tmp varchar(100)
set @tmp='12/05/1978'

select convert(varchar(10), cast(@tmp as datetime), 121) as FormattedDate





Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-25 : 08:57:52
quote:
Originally posted by sent_sara

how to convert the below dateformat to '1978-05-12'

DEclare @tmp varchar(100)
DEclare @test varchar(10)
set @tmp='12/05/1978'
select @test=convert(char(10),@tmp,102)
print @test



1 Where do you want to show Formatted date?
2 Always use Proper DATETIME to store dates and let front end do formation(If you use it)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -