How to format the date?

JCel

Active member
Joined
Jun 15, 2009
Messages
30
Programming Experience
Beginner
Hi how to format the date to dd-mm-yyyy that has to be assigned to a TextBox control? My current date format is mm/dd/yyyy
 
Where are you getting the date from? If it's a DateTime object you can do .ToString("dd-MM-yyyy") when assigning it to the TB.Text
 
If it's bound select '(Advanced)' in DataBindings property where you select 'Date Time' format and the short date type. Also rather than a Textbox it's better to use a MaskedTextBox and set it's input format to 'Short date'.

Note that setting the date string formats explicitly to a format that only conforms to a single culture rarely is a good idea. In JB example using the short date format "d" would be culture independent, and same as using the ToShortDateString method.
 
No, ToShortDateString is the culture independent "d" format, it displays the short date according to how short date strings is configured in computer regional settings.
 
Hi john,
I have used txtDate.Text=Now.ToShortTimeString and its output is in MM-DD-YYYY format...

Also your solution sounds good but the problem is I cant go and change the regional time to DD-MM-YYYY format in all PC?
so plz suggest some other method that can be coded in pgm...
 
JB has suggested that. Why do you need to display a date string different than the user culture format?
problem is I cant go and change the regional time to DD-MM-YYYY format in all PC?
Neither should you do that.
 
Back
Top