Can anyone tell me how to calculate the diff between two dates without using .net datetime and timestamp classes?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If I couldn’t use the built-in types, I’d try to find another .NET date/time API. I suspect I wouldn’t find one though, given that any sane person would use the built-in ones.
If it’s really just a case of dates, I guess a full date/time API isn’t really required. Parse whatever you get into “days since some epoch” (e.g. Jan 1st 1970) and just do normal subtraction.
Be careful of leap years though – and things get even more fun if you need to cope with the bizarre calendar changes a few centuries back.
Sample code assuming a format of “yyyyMMdd”, not doing any error checking, not coping with dates before 1900, and not worrying about efficiency at all: