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

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
 
S

Stefano \WildHeart\ Lanzavecchia

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);

?
 
M

Morten Wennevik

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

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

Kevin Spencer

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

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
P

Peter Seaman

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
 
G

Guest

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
 
P

Peter Seaman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top