C# Convert String to DateTime in ASP.Net

In ASP.Net 2.0 you can easily convert a string type DateTime value to the DateTime variable or you can say an object that further provides you the access to all the DateTime functions. The string type DateTime value must be in any valid format i.e. in the form of valid format specifier. It should be dd/MM/yyyy hh:mm:ss tt or any part i.e. Date or Time. You can learn the DateTime formats from the previous samples also.

Try the following sample to convert the Date or Time input string into the DateTime object that will return the different parts of the DateTime string value:

Enter Date:
Date/Time Part Name Output
Day : 18
Month : 5
Year : 2013
Hours : 16
Minutes: 30
Seconds : 45
Date : Saturday, May 18, 2013
Time : 4:30:45 PM
  • HIRE EzineASP.Net Developers