473,657 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ 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.S ubtract(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 2477
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.Compar eTo(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.S ubtract(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******** ******@TK2MSFTN GP15.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.Compar eTo(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.S ubtract(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******** ******@TK2MSFTN GP09.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
5804
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 held in memory and therefore fast, without risk of damaging real files, and with none of the messiness of leftover files after testing. Googling the archives and the web suggests that only I and Remy Blank have done much along these lines. I...
1
2287
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 status page. Currently webmasters use MS Frontpage to connect from their local PC to our development servers, work on their sites, then publish from there to our live servers.
2
22789
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: operator delete(void*) (vg_replace_malloc.c:156) ==11604== by 0x804A1BA: __gnu_cxx::new_allocator<Foo>::deallocate(Foo*, unsigned) (new_allocator.h:86) ==11604== by 0x8049C08: std::_Vector_base<Foo, std::allocator<Foo> >::_M_deallocate(Foo*,...
8
25219
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
75170
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
3773
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 code. for example, this is bad practice: header.h #include <string> using std::string;
0
1345
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 info the file is no longer up-to-date with our CVS-repository. Also if I check the file in to the CVS-repository the assembly info is no longer up-to-date. I've seen the 1.0.* -trick and I can accept it on the AssemblyVersion but the...
3
1650
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 be able to return a meaningful value (e.g. Divide by zero) and null (or other default) is returned instead. This is not a fatal error, so processing can continue on the rest of the data table. As such, the table may ultimately end up with a...
49
2881
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
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1937
muto222
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.