zimmer9
asked on
Do you know how to ensure that a string date is padded with 0 in ASP.Net using C# and VS2010 in format MM/dd/yyyy ?
I am maintaining an ASP.Net application using C#.
If I have a date string in format "MM/dd/yyyy", for ex: 1/1/2004, do you know how I can convert this so that it gets padded with a high order 0 if it contains one of the months 1 through 9 or the dates 1 through 9.
Thus, 1/1/2014 would be converted to 01/01/2014?
If I have a date string in format "MM/dd/yyyy", for ex: 1/1/2004, do you know how I can convert this so that it gets padded with a high order 0 if it contains one of the months 1 through 9 or the dates 1 through 9.
Thus, 1/1/2014 would be converted to 01/01/2014?
ASKER
I had tried
string dtCreatedmod = String.Format("{0:MM/dd/yy yy}", sdtCreated);
But BEFORE and AFTER execution, sdtCreated has the value 1/4/2017 and dtCreatedmod has the same value of 1/4/2017.
I was hoping to see 01/04/2017. I wondered what I am doing wrong?
string dtCreatedmod = String.Format("{0:MM/dd/yy
But BEFORE and AFTER execution, sdtCreated has the value 1/4/2017 and dtCreatedmod has the same value of 1/4/2017.
I was hoping to see 01/04/2017. I wondered what I am doing wrong?
please use date.toString() instead of string.format:
https://msdn.microsoft.com/en-us/library/zdtaw1bw(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/zdtaw1bw(v=vs.110).aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window