473,471 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using DateTime to check "minor" status

Given a DateTime variable, what's the best way to check "minor" status
(i.e., less than age 18 years) based on today's date? I came up with this:

Dim minor As Boolean = true
'dtDOB is a DateTime variable set to Date of Birth
If (DateTime.Now.Subtract(dteDOB.Value.AddYears(18)). TotalDays >= 0) Then
minor = false
End If

This appears to work, but seems a little obfuscated. I was just wondering
if there was an easier way, and also to double-check my sanity and make sure
that my logic/implementation aren't screwy.

Thanks
Nov 21 '05 #1
4 2469
Michael,
I normally define a variable (possible a readonly class field) that is the
"minor" date, then compare my date of birth to it.

Something like:

Dim minorDob As DateTime = DateTime.Today.AddYears(-18)
Debug.WriteLine(minorDob, "minor date")

For Each dob As DateTime In New DateTime() {#3/18/1987#,
#3/19/1987#, #3/20/1987#, #3/21/1987#, #3/22/1987#}
If minorDob.CompareTo(dob) < 0 Then
Debug.WriteLine(dob, "minor")
Else
Debug.WriteLine(dob, "adult")
End If
Next

Hope this helps
Jay

"Michael C#" <xy*@abcdef.com> wrote in message
news:07******************@fe10.lga...
Given a DateTime variable, what's the best way to check "minor" status
(i.e., less than age 18 years) based on today's date? I came up with
this:

Dim minor As Boolean = true
'dtDOB is a DateTime variable set to Date of Birth
If (DateTime.Now.Subtract(dteDOB.Value.AddYears(18)). TotalDays >= 0) Then
minor = false
End If

This appears to work, but seems a little obfuscated. I was just wondering
if there was an easier way, and also to double-check my sanity and make
sure that my logic/implementation aren't screwy.

Thanks

Nov 21 '05 #2
Michael,

I find it nice code, when this is not to precise for you, than it will work
in my opinion as well.

\\\
If dteDOB.Ticks > Now.AddYears(-18).Ticks Then
minor = True
End If
///

I hope this helps,

Cor
Nov 21 '05 #3
Thanks Jay, I appreciate the feedback! Definitely a lot cleaner than my
version.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uA**************@TK2MSFTNGP15.phx.gbl...
Michael,
I normally define a variable (possible a readonly class field) that is the
"minor" date, then compare my date of birth to it.

Something like:

Dim minorDob As DateTime = DateTime.Today.AddYears(-18)
Debug.WriteLine(minorDob, "minor date")

For Each dob As DateTime In New DateTime() {#3/18/1987#,
#3/19/1987#, #3/20/1987#, #3/21/1987#, #3/22/1987#}
If minorDob.CompareTo(dob) < 0 Then
Debug.WriteLine(dob, "minor")
Else
Debug.WriteLine(dob, "adult")
End If
Next

Hope this helps
Jay

"Michael C#" <xy*@abcdef.com> wrote in message
news:07******************@fe10.lga...
Given a DateTime variable, what's the best way to check "minor" status
(i.e., less than age 18 years) based on today's date? I came up with
this:

Dim minor As Boolean = true
'dtDOB is a DateTime variable set to Date of Birth
If (DateTime.Now.Subtract(dteDOB.Value.AddYears(18)). TotalDays >= 0) Then
minor = false
End If

This appears to work, but seems a little obfuscated. I was just
wondering if there was an easier way, and also to double-check my sanity
and make sure that my logic/implementation aren't screwy.

Thanks


Nov 21 '05 #4
Thanks Cor, very nice simple code. I appreciate it.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
Michael,

I find it nice code, when this is not to precise for you, than it will
work in my opinion as well.

\\\
If dteDOB.Ticks > Now.AddYears(-18).Ticks Then
minor = True
End If
///

I hope this helps,

Cor

Nov 21 '05 #5

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

Similar topics

9
by: Peter Hansen | last post by:
The term "mock filesystem" refers to code allowing unit or acceptance tests to create, read and write, and manipulate in other ways "virtual" files, without any actual disk access. Everything is...
1
by: Rob Meade | last post by:
Hi all, Ok - minor problem - looking for work-a-rounds... I want to offer on our organisations intranet a support site for our webmasters, one of the features I'd like to add is a server...
2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
8
by: Nick Li | last post by:
Hi, I am trying to writing a c program to send email using system() function call on Unix(Sun Solaris). I tried the following: #include <stdio.h> #include <stdio.h> int main(void) {
35
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
0
by: per9000 | last post by:
Hi all, we use CVS to manage versions of our code. Since the CVS keeps track of everything we need I want to synchronize the assembly info with CVS. The problem is that if I update the assembly...
3
by: roger.dunham | last post by:
Hi there, I am writing an application that performs calculations on records within a data table. There may be many records in a data table. There are situations where the calculation may not...
49
by: aarklon | last post by:
Hi all, See:- http://www.cs.princeton.edu/introcs/faq/c2java.html for C vs Java in number crunching http://husnusensoy.blogspot.com/2006/06/c-vs-java-in-number-crunching.html
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
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.