Get DateTime.Now but exact 16 years ago..but how?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I will get the date from now (DateTime.Now is 18.12.2003) but exact
16 years ago (18.12.1987).

when I make something like this:


//we set min. employee age to 16 years
TimeSpan minEmployeeAge = new TimeSpan(5840,0,0,0);

DateTime maxDate = DateTime.Now - minEmployeeAge;



maxDate return me the date of 22.12.1987 .
Can someone tell me how to make it to get the exact date?


regards,


gicio
 
I will get the date from now (DateTime.Now is 18.12.2003) but exact
16 years ago (18.12.1987).

when I make something like this:
//we set min. employee age to 16 years
TimeSpan minEmployeeAge = new TimeSpan(5840,0,0,0);
DateTime maxDate = DateTime.Now - minEmployeeAge;

maxDate return me the date of 22.12.1987 .
Can someone tell me how to make it to get the exact date?

I guess you are expecting 18.12.2003? Given that there are leap years, you
cannot simply multiply 365 by 16 and expect it to give you the same day.

How about:
DateTime maxDate = DateTime.Now.AddYears(-12);

?
 
You can do it much simpler by adding -16 years to the current date

DateTime maxDate = DateTime.Now.AddYears(-16);
 
DateTime maxDate = DateTime.Now.AddYears(-minEmployeeAge);

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Interesting question. What do you mean by "exactly 16 years". A year is
ambiguous. A sidereal year is about 365.25 days, a calendar year is
sometimes 365 days, sometimes 366 days. And leap seconds get added
sometimes. If I wanted to be really difficult I might point out that a
date is also geographically dependant.

Peter Seaman
 
Hi!

(in line)


Peter Seaman said:
Interesting question. What do you mean by "exactly 16 years". A year is
ambiguous. A sidereal year is about 365.25 days, a calendar year is
sometimes 365 days, sometimes 366 days. And leap seconds get added


I know... but when you for example are born at 12.12.1950 you
celebrate your birthday every! year at 12.12 and not one year at 11.12.
and the other at 12.12.

my statemant "exactly 16 years" is not correct choosen ;)
sorry!!!



gicio
 
Thanks, I was only trying to be mischevious. I often wonder when you should
celebrate your birthday - (a) On the day when your birthdate arrives in the
place you are now or (b) On the day when your birthdate arrives in the place
where you were born. These can be different!

Peter Seaman
 
Back
Top