Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a data table that contains a column with datatype datetime. When i execute the query to fill the table in sql server i get the dates in dd/MM/yyyy format. When i fill the table using the same query it fills the column in MM/dd/yyyy format. I want to have the date format as dd/MM/yyyy in the datatable. How can i get it possible.
Thanks..
Posted

1 solution

There could be two ways to do this -
1) Handle the conversion at the database level. You can use the Convert method [^]to this in your query.
2) Handle it once data comes back to the form. If you want to handle this in your code, you can convert the datetime in the source of the datatable, using toString() (http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^])
 
Share this answer
 
Comments
sanomama 2-Aug-11 1:50am    
5 up
Abhinav S 2-Aug-11 3:18am    
Thanks.
shaijuvjohn 2-Aug-11 2:20am    
I stores the date values in database as varchar type. When i convert them as date time it gives the result format as yyyy/MM/dd. I have converted it using the following two methods.
1 . SELECT CONVERT(varchar(10), vouchers.vchdate,103) AS Vchdate FROM vouchers
- it resulted the correct format. but when fill the datatable using this query the date again converts to MM/dd/yyyy automaticlly, may be due to the datatype of the column is datetime.
2. SELECT CONVERT(datetime,vouchers.vchdate) AS Vchdate FROM vouchers
- it results the values in yyyy/MM/dd format.
So the problem remains same.

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