Answered by:
DateTime Conversion

Question
-
Hello
i need to convert DateTime to int32 in asp.net c#.I am using ajax calender extender control to calculate age
Thursday, May 10, 2012 12:42 PM
Answers
-
If the error is on the second line then you'll need to use DateTime.Parse, TryParse, or ParseExact to convert the string into a datetime.
- Marked as answer by Lisa Zhu Tuesday, May 22, 2012 6:13 AM
Thursday, May 10, 2012 5:09 PM
All replies
-
Best would be to put it into format yyyyMMdd, so you can do it like:
DateTime date = ... int dateNumber = int.Parse(date.ToString("yyyyMMdd"));
Mitja
Thursday, May 10, 2012 12:47 PM -
I will show my code
Here is my code
DateTime now = DateTime.Today;
DateTime s = dobcalender.SelectedDate;
int years = now.Year - s.Year;
if (now.Month < s.Month || (now.Month == s.Month && now.Day < s.Day))
--years;
tb_age.Text = years.ToString();Thursday, May 10, 2012 12:53 PM -
So, what is the problem. I dont see it any from your code snippet.
Mitja
Thursday, May 10, 2012 1:05 PM -
Error 2 Cannot implicitly convert type 'string' to 'System.DateTime'
Thursday, May 10, 2012 4:43 PM -
If the error is on the second line then you'll need to use DateTime.Parse, TryParse, or ParseExact to convert the string into a datetime.
- Marked as answer by Lisa Zhu Tuesday, May 22, 2012 6:13 AM
Thursday, May 10, 2012 5:09 PM