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)
 sql - date

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2005-03-10 : 10:08:49
There is a string as say: '01/02/1992'
How can I get '01/02/92'
Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-10 : 10:11:58
declare @date varchar(10)
set @date = '01/02/1992'
select @date, left(@date, 6) + right(@date, 2)

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

Arti
Starting Member

5 Posts

Posted - 2005-03-10 : 15:00:33
You can use convert function also.

Select Convert(Varchar(8), getdate(), 112)
Go to Top of Page

lazerath
Constraint Violating Yak Guru

343 Posts

Posted - 2005-03-10 : 17:57:38
SELECT CONVERT(VARCHAR(8), CAST('01/02/1992' AS DATETIME), 1)
Go to Top of Page

PW
Yak Posting Veteran

95 Posts

Posted - 2005-03-10 : 18:03:16
>>How can I get '01/02/92'

Whay would you want to convert a perfectly good, Y2K safe date, and convert it into a form with ambiguous century ?
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-03-10 : 23:04:14
Because he's using SQL to display his data, which in general is a REALLY bad idea. It should be handled by the application. In the interests of formatting your data with SQL though, I once again present my famous "here are all the date formats":


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), 'SELECT CONVERT(VARCHAR,GETDATE(),' + CAST(@min AS VARCHAR(5)) + ')'

NEXT_LOOP:

SELECT @min = @min + 1
END




MeanOldDBA
derrickleggett@hotmail.com

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

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-03-10 : 23:14:25
Cool MODBA!

I didn't realize the options went beyond the little convert style chart in BOL. Thanks

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -