Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am developing an asp web application in that many web forms have Date field, i am giveing date and seveing in sql server 2005 database it storing date like MM/DD/YYYY. But whenever i retraives that same deta and displaying into textbox that time date format is like DD/MM/YYYY.

Because of this format change asp web application throwing format exception.

Please anybody let me to how retrive date value in MM/DD/YYYY format from sql server.

Thanks
Uday
Posted
Comments
Amir Mahfoozi 22-Oct-11 4:51am    
did you succeed ?

Have a look at using CAST and CONVERT - http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx[^].

More specifically for your case, have a look at code 101.
 
Share this answer
 
Firstly, You should make sure that you are storing your data in SQL Date fields - I assume you are or you would not see the problem you describe.

Secondly, you should not be making decisions about display date format at all, and you should not assume that the user is entering dates in any particular format either. Bear in mind that the users of a website could be anywhere in the world, and will expect dates to be entered and displayed in their current local format. So, don't use a textbox: use a Calender control instead - that will also validate the dates entered by the user to ensure that they actually exist.
 
Share this answer
 
use this in your select statement :

SQL
CONVERT(char(10), OrderDate, 101) newdate


want to know more about 101 ? read here :
http://msdn.microsoft.com/en-us/library/ms187928.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900