Sunday, March 20, 2016

ASP.NET C#


Error:

String was not recognized as a valid Date Time.

                       When You get a age from birth date to current date, then use code listed below:

Code:

            int birth_year = Convert.ToDateTime("15/12/1996").Year;
            int now_year = DateTime.Now.Year; // 2016
            int age = now_year - birth_year;
            age.Text = aged.ToString(); 

 Solution: 

                      Although the above solutions are effective, you can also modify 
                      the webconfig file with the following...
<configuration>                       
   <system.web>                       
     <globalization culture="en-GB"/> 
   </system.web>                      
</configuration>                      
 Output:
 20