Change string to date time data type with specific format..

Here we will change data type from datetime type to string 
Description: 

 Actually when we need date time value in specific format like (dd/mm/yyyy) or in other  format,  while we are using datetime as a string variable.
In this case it becomes a little bit typical to change string variable value to a specific format. So here we need to change our string variable value to a specific datetime format after that change it to a format you want to change
                      
Steps:

*      ParsestrExpiryDateTo’ string into proper date time format in which string is already.

*     ‘dtStrExpiryDateTo’ variable which is storing datetime parsed value change it to a particular format you want to change. In this case it is changing in ("mm/dd/yyyy") format.


C#:

DateTime dtStrExpiryDateTo = DateTime.ParseExact(strExpiryDateTo, "mm/dd/yyyy", null);
               strExpiryDateFrom = dtStrExpiryDateTo.ToString("mm/dd/yyyy");

Comments

Post a Comment