Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

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?
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

you could use String.Format like this:

String.Format("{0:MM/dd/yyyy}", dt);

Open in new window

Avatar of zimmer9

ASKER

I had tried

string dtCreatedmod = String.Format("{0:MM/dd/yyyy}", 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?
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial