SQLServerCentral.com / SQL Server 2008 - General / SQL Server 2008 / String to date conversion issue / Latest PostsInstantForum.NET v99.99.99SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comFri, 09 Dec 2016 10:56:33 GMT20RE: String to date conversion issuehttp://www.sqlservercentral.com/Forums/Topic1488265-391-1.aspxYou have to separate the data format the user enters vs. what's stored in the db. It's OK in your app to have the user enter "mon. dd, yyyy" if that's what you prefer. However, you should store an actual date or datetime column in the db, not the text the user enters.Likewise, you might allow users to enter a SSN as ###-##-####, but you shouldn't store the dashes in the db.Use a computed column to add any formatting for output; persist that computed column only if you have to (you [i]almost never[/i] need to persist the formatted data).Thus, you would have a computed column that would redisplay the data back to the user in the format they expect. The internal SQL storage format (which, for data/datetime data types is actually integer(s)) should be transparent, and therefore irrelevant, to the user.Mon, 26 Aug 2013 10:05:59 GMTScottPletcherRE: String to date conversion issuehttp://www.sqlservercentral.com/Forums/Topic1488265-391-1.aspx[quote][b]simflex-897410 (8/25/2013)[/b][hr]However, the issue we have now is that when we try to update same date value, it stores a different formatted value like:[/quote]And now you understand why storing a formatted date of any kind is one of the worst database sins there is. Store all dates using one of the date/time or date datatypes and format only when consumed. If you're really pressed, create a persisted calculated column to do the formatting for you but don't store the actual data as a formatted date/time of any type.As a bit of a sidebar, the app should check what the user has entered to see if it can even be converted to a date and, if it can, IT should pass the date as a datetime or date datatype. If it's not a valid date, the app should alert the user without even touching the database.Sun, 25 Aug 2013 20:51:24 GMTJeff ModenString to date conversion issuehttp://www.sqlservercentral.com/Forums/Topic1488265-391-1.aspxUsers of our app currently store date values in the following format:[b]Mon. dd, yyyy.[/b]Example: [b]Sept. 23, 2013[/b]We would like to convert these date values to MM/dd/yyyy, eg, 9/23/2013 and the code below does just that.[code="sql"]SELECT CONVERT(VARCHAR(10), CONVERT(DATETIME, SUBSTRING('Sept. 23, 2013', 0, 4) + ' ' + SUBSTRING('Sept. 23, 2013',6,9), 107), 101)[/code]When we run this code, now, we get above date, for instance, formatted to 9/23/2013.However, the issue we have now is that when we try to update same date value, it stores a different formatted value like:Sep 23 2013 12:00AMNotice that first, Sept. is now Sep which is wrong because t and period (.) are missing.Simply put, when we update a date value, it needs to follow similar format as this -&gt; [b]Sept. 23, 2013[/b]Any ideas how to modify above query to produce similar result when a date value is updated?Thanks a lot in advanceSun, 25 Aug 2013 16:53:37 GMTsimflex-897410