Here’s my code:
DateTime date1 = new DateTime(byear, bmonth, bday, 0, 0, 0);
DateTime datenow = DateTime.Now;
DateTime date2 = datenow - date1
On the last line I am getting this error:
Error 1 Cannot implicitly convert type ‘System.TimeSpan’ to ‘System.DateTime’
How do I subtract two dates?
Well the point is that if you think of it, subtracting a date to another should not yield a date, it should yield a time span. And that is what happens when you use DateTime.Subtract().
This will make your current code work.
If on the other hand you want to subtract, let’s say, one year from your date, you can use: