Sep 12, 2001 #1 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>
I have to convert a datetime to a varchar(8) in a ddmmyy format. can someone help me with this? Björn >:O>
Sep 12, 2001 1 #2 Tim1 Programmer Mar 27, 2001 242 GB 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 Upvote 0 Downvote
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
Sep 12, 2001 #3 Tim1 Programmer Mar 27, 2001 242 GB 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 Upvote 0 Downvote
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
Sep 12, 2001 Thread starter #4 INFORMAT Programmer Jan 3, 2001 121 BE thank you tim. Your second post was very helpfull. thanks a lot Bjorn >:O> Upvote 0 Downvote
Sep 12, 2001 #5 tlbroadbent MIS Mar 16, 2001 9,982 US 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),'/','') Upvote 0 Downvote
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),'/','')