Windows Develop Bookmark and Share   
 index > Windows Forms Designer > how to set a format for date
 

how to set a format for date

hello
I want to kno that how i can set a format for date in sql like at the time of entering one should first enter day then month and then year.

desperate for help  Tuesday, August 04, 2009 4:20 PM
Hi,

When you insert date into database using sql script. It depend on your local computer format setting. For example, if your computer region and language setting has set format to MM/DD/YYYY, so the following sql
Insert into Table1(DateColumn)
values('8/6/2009')
will insert Augest 6 2009 into database. And the following is equal
Insert into Table1(DateColumn)
values('2009/8/6')

But if you use
Insert into Table1(DateColumn)
values('6/8/2009')
it will insert June 8 2009 into database.

If you want to change that and make the first is day and second is month, you may change the region and language setting.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, August 06, 2009 3:33 AM
Hi,

Kira Qiran describing wellfor date formating, but if you like to format custom dateaccording to ur application requirment and accepting only the dd/mm/yyyy format is a valid date format. then use the following code for custom date formating .

// Creating a Global Culture specific to our application.
System.Globalization.CultureInfo cultureInfo =
new System.Globalization.CultureInfo("en-US");
// Creating the DateTime Information specific to our application.
System.Globalization.DateTimeFormatInfo dateTimeInfo =
new System.Globalization.DateTimeFormatInfo();
// Defining various date and time formats.
dateTimeInfo.DateSeparator = "/";
dateTimeInfo.LongDatePattern = "dd/MMM/yyyy";
dateTimeInfo.ShortDatePattern = "dd/MMM/yy";
// Setting application wide date time format.
cultureInfo.DateTimeFormat = dateTimeInfo;
// Assigning our custom Culture to the application current thread.
Application.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
//End Culture Info

After inserting the above application date format,

if your enter the date in the format and convert.TodateTime("12/30/2009") it will throw error message invalid date format because you r sitting the date format "dd/mm/yyyy""

Ok Good luck.
Malik M.Shahid  Thursday, August 06, 2009 8:11 PM
Hi, use the String.Format method. Take a look at this post I wrote on my blog about that.
:. HUGONNE .: Please mark as answer if the post helps
Hugonne  Thursday, August 06, 2009 9:22 PM
Hi,

When you insert date into database using sql script. It depend on your local computer format setting. For example, if your computer region and language setting has set format to MM/DD/YYYY, so the following sql
Insert into Table1(DateColumn)
values('8/6/2009')
will insert Augest 6 2009 into database. And the following is equal
Insert into Table1(DateColumn)
values('2009/8/6')

But if you use
Insert into Table1(DateColumn)
values('6/8/2009')
it will insert June 8 2009 into database.

If you want to change that and make the first is day and second is month, you may change the region and language setting.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, August 06, 2009 3:33 AM
Hi,

Kira Qiran describing wellfor date formating, but if you like to format custom dateaccording to ur application requirment and accepting only the dd/mm/yyyy format is a valid date format. then use the following code for custom date formating .

// Creating a Global Culture specific to our application.
System.Globalization.CultureInfo cultureInfo =
new System.Globalization.CultureInfo("en-US");
// Creating the DateTime Information specific to our application.
System.Globalization.DateTimeFormatInfo dateTimeInfo =
new System.Globalization.DateTimeFormatInfo();
// Defining various date and time formats.
dateTimeInfo.DateSeparator = "/";
dateTimeInfo.LongDatePattern = "dd/MMM/yyyy";
dateTimeInfo.ShortDatePattern = "dd/MMM/yy";
// Setting application wide date time format.
cultureInfo.DateTimeFormat = dateTimeInfo;
// Assigning our custom Culture to the application current thread.
Application.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
//End Culture Info

After inserting the above application date format,

if your enter the date in the format and convert.TodateTime("12/30/2009") it will throw error message invalid date format because you r sitting the date format "dd/mm/yyyy""

Ok Good luck.
Malik M.Shahid  Thursday, August 06, 2009 8:11 PM
Hi, use the String.Format method. Take a look at this post I wrote on my blog about that.
:. HUGONNE .: Please mark as answer if the post helps
Hugonne  Thursday, August 06, 2009 9:22 PM
Thank you all for your help.I hope that this will solve my problem
desperate for help  Sunday, August 09, 2009 4:46 PM

You can use google to search for other answers

Custom Search

More Threads

• Inherited Control - How to Set Prop in Win Form which Will USe Control
• problem in CheckBOx checkedchanged event..
• Problems with TypeConverter when using arrays
• IDesignerSerializationService and childcontrols
• DataGridView and Graphics
• Toolbox default tab when designing a WinForm
• How to make splesh screen like Adobe Acrobat
• Change control cursor to cursor from .cur in designer
• General questions Behaviors
• Custom UITypeEditor not working for properties of type "System.Windows.Forms.Control"