I have this function...
private string dateConvert(string datDate) { System.Globalization.CultureInfo cultEnGb = new System.Globalization.CultureInfo("en-GB"); System.Globalization.CultureInfo cultEnUs = new System.Globalization.CultureInfo("en-US"); DateTime dtGb = Convert.ToDateTime(datDate, cultEnGb.DateTimeFormat); datDate = dtGb.ToString(cultEnUs.DateTimeFormat.ShortDatePattern); return datDate; }
But I want it with the leading zero still on lower digits (1-9) so the date is 11-09-2009 (mm-dd-yyyy)...
Now If I wasn't converting it id use string.Format("{0:d}", dateVar) how do I do this in the conversion?
***** Solution *****
Used a slightly modified version of the answer below (i.e. one that would render).
Convert.ToDateTime(datDate).ToString("MM-dd-yyyy");
Step 1: Get the Number N and number of leading zeros P. Step 2: Convert the number to string using the ToString() method and to pad the string use the formatted string argument “0000” for P= 4. val = N. ToString("0000");
The day of the month. Single-digit days will have a leading zero. The abbreviated name of the day of the week.
Senior Member. If the month is written using letters then it would be unusual to add a leading zero to the date. With dates entirely in numbers, leading zeroes for the date and month are common, but not universal.
return dateTimeValue.ToString("MM-dd-yyyy");
Can't you use the string.Format
after you've done the conversion?
ie return string.Format("{0:d}", datDate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With