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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 saving date as varchar in the date format

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2013-02-08 : 12:30:59
I have a table Customer where there is a field Customer_date which is of varchar(50) datatype.

I am getting data from another table where the date is of varchartype but when i am doing the transfer the dates are getting store as Feb 25 2013 12:00:00 instead of 02/25/2013...

I am doing the transfer through .cs page of ASP.NET. Can someone give me suuggestions...

thank you in advance

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-08 : 12:43:59
If at all there is a choice, you should change the data type of the Customer_date column to DATE or DATETIME. That would be beneficial for a number of reasons.

That aside, if you want to keep it as varchar(50), you can convert teh long format to the mm/dd/yyyy format using this:
CONVERT(VARCHAR(50), CAST( 'Feb 25 2013 12:00:00' AS DATETIME),101)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-08 : 23:02:49
also see

http://visakhm.blogspot.in/2011/12/why-iso-format-is-recommended-while.html

http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -