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
 Date modification

Author  Topic 

Claire_Toronto
Starting Member

11 Posts

Posted - 2011-08-10 : 18:16:20
Hi there,

I have a date stamp that looks like: 20110726 and I want it to be like: 2011-07-26 so I need the hyphens... but in some rows the date may be like 07262011 so I need that to change to: 2011-07-26 so it gets complicated... can anyone help please?

thank you

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-10 : 18:20:59
Change the data type to date/time and then handle formatting in your application layer.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Claire_Toronto
Starting Member

11 Posts

Posted - 2011-08-10 : 18:39:51
hi Tara,

I tried this but it gives me the time:

Code:
convert(datetime, start_date, 120) as startdate

Result:
2011-08-02 00:00:00.000

when I remove time I get an error: convert(date, start_date, 120) as startdate

Error:
Type date is not a defined system type.

can you help? thanks :)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-10 : 18:42:19
Style 120 includes the time. You can either use a style that removes it or strip it out in your application. But really you need to change the data type in the actual table so that you don't have this problem.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -