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.
| Author |
Topic |
|
ramya_rav2000
Starting Member
2 Posts |
Posted - 2005-11-18 : 15:47:47
|
| Hi I have a varchar field with values like "Jun 13 1995 12:" I want to change the type of the field to Date and the format of the values to "mm/dd/yyyy".If I change the type of the field in the design view to Date, SQL gives me an error saying that the type cannot be changed and data would be lost.So I think changing the dates to the mm/dd/yyyy format first and then changing the field type from varchar to date would work.Can someone please help me as how to do this.Thanks |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
ramya_rav2000
Starting Member
2 Posts |
Posted - 2005-11-18 : 16:59:10
|
| Hi,Thanks for your reply. Jun 13 1995 12: is an example of one data in the field. I want to change the format of all the data in all the records to mm/dd/yyyy. Is there a way I can do this ? There are 100's of records in the table.Thanks |
 |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2005-11-18 : 17:48:48
|
| I think you're going to have to pull out the individual pieces of the string using the string functions. I'd look in Books Online for SUBSTRING. You should be able to use it to craft a string that SQL Server will convert to a date.Or SELECT CAST(LEFT('Jun 13 1995 12:', 11) AS DATETIME) works fine on my machine.===============================================Creating tomorrow's legacy systems today.One crisis at a time. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-18 : 23:50:17
|
| Hereafter dont use varchar or any other data type to store dates. DATETIME data type is specifically for storing Dates and dont worry on which format to store it. Let SQL Server stores it in its way and when you show the data in presentation layer format it there to the format you want to formatMadhivananFailing to plan is Planning to fail |
 |
|
|
spinoza
Starting Member
49 Posts |
Posted - 2006-01-07 : 11:02:39
|
| ÇÉ all,I have the following query from an asp page...select ARTICLE.title, ARTICLE_RATING.comments, ARTICLE_RATING.rating, PORTAL_MEMBERS.m_name, ARTICLE_RATING.rate_datefrom ARTICLE, ARTICLE_RATING, PORTAL_MEMBERSwhere article.article_id= article_rating.articleAND ARTICLE_RATING.rate_by=PORTAL_MEMBERS.member_idorder by m_nameThe field ARTICLE_RATING.rate_date is stored date values but in my database has a nvarchar property...It is stored like that 20060107213345 where the first 4 digits are the year the other two the month... the date (07) and the time (213345)...I need to represent it through the query as a Date... Can someone help me how can trnform the above query??? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-09 : 01:22:16
|
| Use Proper DateTime data type to store DatesHere is one of the methodsdeclare @n nvarchar(20)set @n='20060107213345'select cast(left(@n,8)+' '+substring(@n,9,2)+':'+substring(@n,11,2)+':'+substring(@n,13,2) as datetime) as NewDateMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|