Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am using sql server 2008 and .net 2.0 .My Sql Server has MM/DD/yyyy format

when i am trying to insert date data using Query Analyzer it needs mm/dd/yyyy format.But when i use the .net code to pass date data as procedure format i need to change to dd/mm/yyyy format for inserting data same as for querying the date filed from .net need to change the format dd/mm/yyyy to get the data otherwise it throws error. why i need to change my date format .Anybody can answer for it please...
Posted
Comments
VJ Reddy 16-May-12 3:02am    
Thank you for accepting the solution :)

The Date Format in .NET depends upon the CurrentCulture unless a different FormatProvider is specified in the method producing the string output of DateTime value.
In the following code the first two printed DateTime values are governed by the CurrentCulture whereas in the third the FormatProvider given as an argument to ToString method has overridden the CurrentCulture format.

C#
DateTime today = DateTime.Now;
Thread.CurrentThread.CurrentCulture = 
        System.Globalization.CultureInfo.GetCultureInfo("hi-IN");
Console.WriteLine (today);

Thread.CurrentThread.CurrentCulture = 
        System.Globalization.CultureInfo.GetCultureInfo("en-US");
Console.WriteLine (today.ToString());

Console.WriteLine (today.ToString(System.Globalization.CultureInfo
        .GetCultureInfo("hi-IN").DateTimeFormat));

//15-05-2012 15:56:38
//5/15/2012 3:56:38 PM
//15-05-2012 15:56:38


Please try to interpret the above info in the context of your code. I think it may be helpful.
 
Share this answer
 
Comments
Maciej Los 15-May-12 10:13am    
Very good answer, my 5!
VJ Reddy 15-May-12 10:17am    
Thank you, losmac :)
Sandeep Mewara 15-May-12 10:33am    
Good answer. 5!
VJ Reddy 15-May-12 10:41am    
Thank you, Sandeep :)
Solution no 1 is very good.

I think you can use SET DATEFORMAT[^] command to change date format for SQL Server.
 
Share this answer
 
Comments
VJ Reddy 15-May-12 10:19am    
Good answer. 5!
Maciej Los 15-May-12 10:23am    
Thank you ;)

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