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
 General SQL Server Forums
 New to SQL Server Programming
 Formating

Author  Topic 

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-09-16 : 09:20:53
I looked around the forums and didn't see the question that I am trying to figure out.

I have a date that is datetime format like this.....
1999-04-01 00:00:00.000

I need to convert it so it looks like this...
19990401

How do I do that?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-16 : 09:26:23
This is a presentation issue. You should be trying to do this at your front end application. What's the front end you're using?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-16 : 09:27:08
quote:
Originally posted by werhardt

I looked around the forums and didn't see the question that I am trying to figure out.

I have a date that is datetime format like this.....
1999-04-01 00:00:00.000

I need to convert it so it looks like this...
19990401

How do I do that?


Where do you want to show formatted dates?

Madhivanan

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

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-09-16 : 09:32:10
I guess the front of this would be Microsoft SharePoint, but I would like to see it done in SQL if possible. The reason why I need to change this is because I need to add another field to this. We are combinding our provider ID which the field is called pcsa_pro + the effective date which is pcsp_eff.

So the end result would look like this....
the first eight number are the ID and the rest is the effective date.

0000000219990401
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-16 : 09:35:26

select pcsa_pro+convert(datetime,pcsp_eff,112) from table

Madhivanan

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

X002548
Not Just a Number

15586 Posts

Posted - 2008-09-16 : 09:51:29
....this is a bad idea

[code]


DECLARE @d datetime, @id int

SELECT @d = '1999-04-01 00:00:00.000', @id = 2

SELECT RIGHT(REPLICATE('0',8)+CONVERT(varchar(10),@id),8)+CONVERT(varchar(10),@d,112)


[/CODE]



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -