473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
Nov 18 '05 #1
11 1368

<gi***@gmx.de> wrote:

I will get the date from now (DateTime.Now is 18.12.2003) but exact
16 years ago (18.12.1987). Can someone tell me how to make it to get the exact date?


DateTime dt = DateTime.Now;
dt = dt.AddYears(-16);
// Bjorn A
Nov 18 '05 #2
DateTime.Now.Year - 16

Tamir

www.tcon.co.il

<gi***@gmx.de> wrote in message news:br************@news.hansenet.net...
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

Nov 18 '05 #3
Hi,

DateTime dt = DateTime.Now;

Console.WriteLine(dt.AddYears(-16));
--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

<gi***@gmx.de> wrote in message news:br************@news.hansenet.net...
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

Nov 18 '05 #4

"Bjorn Abelli" wrote:
<gi***@gmx.de> wrote:

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

Can someone tell me how to make it to get the exact date?


DateTime dt = DateTime.Now;
dt = dt.AddYears(-16);


Or even simpler:

DateTime dt = DateTime.Now.AddYears(-16);

// Bjorn A
Nov 18 '05 #5
> 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);

?

--
WildHeart'2k3

Nov 18 '05 #6
You can do it much simpler by adding -16 years to the current date

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

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 18 '05 #7
cool!!!!

thx for the very fastttttttttt help ;)

best regards,

gicio
Nov 18 '05 #8
DateTime maxDate = DateTime.Now.AddYears(-minEmployeeAge);

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

<gi***@gmx.de> wrote in message news:br************@news.hansenet.net...
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

Nov 18 '05 #9
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
Nov 18 '05 #10
Hi!

(in line)
"Peter Seaman" <Peter MS Seaman at StableSoftware.com> wrote in message
news:ef**************@TK2MSFTNGP10.phx.gbl...
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
sometimes. If I wanted to be really difficult I might point out that a
date is also geographically dependant.

Peter Seaman

Nov 18 '05 #11
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
Nov 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
11
by: | last post by:
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...
4
by: Mark | last post by:
Is there a way to convert a char to a DateTime without first converting to a string and using DateTime.Parse or ParseExact? I'm trying to reuse the char which can be reused instead of converting...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.