Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
plz help, i want to convert datetime format.
In my database date save in "mm/dd/yyyy" format but i want to insert date in "dd/mm/yyyy" format.....


Thanks in advance.......
Posted
Comments
Lalit PB 2-Apr-12 7:02am    
I think in database date will always be inserted in yyyy-mm-dd format you cannot insert it in another format,
but if you want that date in another format for processing then you can convert that date and use it, instead of storing date in dd/MM/yyyy.

Try this:
C#
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]
 
Share this answer
 
Comments
dA.d 2-Apr-12 2:37am    
dont change in database just when i insert date in dd/mm/yyyy format which is save in database in mm/dd/yyyy format
Prasad_Kulkarni 2-Apr-12 2:51am    
use this code simply while sending your data to db..
 
Share this answer
 
Your format in the database is not culture specific. It is the conversion to a string that is culture specific. If you change the culture, then you change the format of the DataTime. What you need to do is change the culture. If you change the culture to US, then you will always be in dd/mm/yy, for France it would be
VB
// C#
// Put the using statements at the beginning of the code module
using System.Threading;
using System.Globalization;
// Put the following code before InitializeComponent()
// Sets the culture to French (France)
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
// Sets the UI culture to French (France)
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");


Just change to "en-US"
 
Share this answer
 
You have to insert in to MM/dd/yyyy formate and fetch data using dd/MM/yyyy format.

SQL
cmd = New SqlCommand("insert into test values( '" & Format(CType(DTPDT.Text, Date), "MM/dd/yyyy") & "'  )", con)
       cmd.ExecuteNonQuery()


for view in dd/MM/yyyy format.

Format(CType(DateTimePicker1.Text, Date), "dd/MM/yyyy")
 
Share this answer
 
You cant change default date set in database.You have to change the format of date while inserting and retrieving.

here is the one way to do this.
C#
this.datetimepicker1.customformat="MM/dd/yyyy";
this.datetimepicker1.format=datetimepicker.format;
_defaultDate=datetimepicker1.text;
this.datetimepicker1.customformat="dd/MM/yyyy";
this.datetimepicker1.format=datetimepicker.format;


hope this helps you..
 
Share this answer
 
Comments
dA.d 2-Apr-12 4:49am    
thanks for reply...
can u give me details for this....

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