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
 Transact-SQL (2000)
 Issue with date conversion

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-09-22 : 13:57:36
I want to have a same as MM-DD-YY but when I insert a record its inserting some other value and when
I use a select statement also it gives a different value..Is my conversion wrong

Declare @good_through_date datetime
SET @through_date=11/11/04

Select through_date=CONVERT(varchar(8), @through_date, 1)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-09-22 : 14:05:33
You need single quotes around your date and your variable names were incorrect for this example:

Declare @good_through_date datetime
SET @good_through_date= '11/11/04'

Select through_date=CONVERT(varchar(8), @good_through_date, 1)

Tara
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-09-22 : 14:47:02
is there any way I can use another conversion method for MM-DD-YY
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-09-22 : 14:50:28
You just want dashes instead of slashes? Isn't that just a display problem? You could use style 105 along with SET DATEFORMAT, but you should be changing the presentation of the data at the presentation layer.

Tara
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-09-22 : 14:52:48
SET DATEFORMAT MDY

or you can do

SELECT @good_through_date = CONVERT(datetime, '11-11-04', 1)

(1=YY and 101=YYYY)

Kristen
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-09-22 : 14:57:54
Tara,
If the user is entering as 12/06/2004 as the date MMDDYY format.How shoud I use the insert in the stored procedure and select in this case
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-09-22 : 15:05:28
You just insert it. I don't understand.

Tara
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-09-22 : 15:42:37
Okay got it it was the problem from the application side that they didn't convert it to the datetime.So it was giving error at the time of select...rest is working fine...Thanks a lot Tara..U have being helping so much..Thanks
Go to Top of Page
   

- Advertisement -