Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert datetime to varchar(8) in ddmmyy format 1

Status
Not open for further replies.

INFORMAT

Programmer
Jan 3, 2001
121
BE
I have to convert a datetime to a varchar(8) in a ddmmyy format. can someone help me with this?

Björn >:):O>
 
Hiya,

Why don't you try:


DECLARE @textdate CHAR(8)

SELECT @textdate = CONVERT(CHAR(2),DATEPART(dd, your_date))

SELECT @textdate = @textdate + CONVERT(CHAR(2),DATEPART(mm, your_date))

SELECT @textdate = @textdate + CONVERT(CHAR(4),DATEPART(yy, your_date))


HTH

Tim
 
Hi again,

Thinking about it, you could also try:

DECLARE @extract_date CHAR(11)
DECLARE @extract_date_c CHAR(8)

SELECT @extract_date = CONVERT(CHAR(11), @your_date, 102)

SELECT @extract_date_c = SUBSTRING (@extract_date,9,2)+SUBSTRING(@extract_date,6,2)+SUBSTRING(
@extract_date,1,4)

Hope one of these gives you what you need,

Tim
 
thank you tim.

Your second post was very helpfull.

thanks a lot

Bjorn >:):O>
 

If you are running SQL 7 or later you can use the REPLACE function with Convert as follows.

Select Replace(Convert(varchar(8),getdate(),3),'/','')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top