Question using date of birth to do a few things at once

psionic98

New member
Joined
Feb 25, 2009
Messages
4
Programming Experience
Beginner
Hi everyone,

I'm new to the forums, so you can kindly scold me for not finding my answers on my own if they are already out there, but I haven't found a direct answer to what I need.

So here's my problem, first off I am working with a developer of an application in which uses .net on the front/back ends, but he is telling me that their system cannot handle the math for this on the front end, and isnt sure how to do it on the back. I want/need it done so I am out finding it for myself.

Heres the problem:

Front end user is asked to enter date of birth(dob) with standard xx/xx/xxxx format. And right after that question is a drop-down menu with text options for under 1month (then prompts for current age in days), under 2 years (prompts for current age in months), over 2 years (prompts for current age in years). What my developer is saying is that their system cannot handle the math to turn DOB into days (current date - dob = days) and then using more math forumas to check if days <=30 that equals under 1 month, and therefore would have the # of days for the text prompts.. then >=31 || <= 730 that equals 2 years or under, and then convert that into months, and >=731 is years and convert it to years.

What I need to know is how to do this in vb, and if possible, how can i use it to also auto choose the field that corresponds to the correct text dropdown.

So we have the fields

dob
dropdown (txt of 3 msgs)
days
months
years

I need to calc DOB into days, then check days against set #s for 1month = 30 days, and then it chooses the dropdown called under 1 month and populates days field with the # of days. and then do the same calcs for months/years fields if possible to.

I apologize if this doesnt make enough sense and would be more than willing to discuss further if someone can take the time to help me. This is for a state mandated system that my company is starting to do electronically instead of manually over the web. And regretfully our developer is smart, but apparently cannot do this.. very annoying.

Any help is greatly appreciated.

Thanks.

Stan

I have a DOB entered on the front end, and currently, due to some restrictions on where this data is sent, there is also a drop-down menu box that has to be filled in which pertains to the actual age. What I need to know is
 
Can't handle the math on the front end!?

VB.NET:
		Dim dob As Date = #6/6/1944#
		Dim ts As TimeSpan = Now.Subtract(dob)
		Dim numberDays As Integer = ts.Days
 
I'm afraid your developer is talking out of his (er.. hat)

Create a form, called MainForm
put a datetimepicker called _birthdayDateTimePicker and a lage called _ageLabel on a form (yes, the underscores are intentional)

Then replace all the form's code with this:

VB.NET:
Public Class MainForm
    Private Sub BirthdayDateTimePicker_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _birthdayDateTimePicker.ValueChanged
        Dim age As TimeSpan = DateTime.Now - _birthdayDateTimePicker.Value

        If age.TotalDays <= 365 Then
            _ageLabel.Text = String.Format("You are under 1 year old. Your age is {0:0} days", age.TotalDays)
        ElseIf age.TotalDays < (365 * 2) Then
            _ageLabel.Text = String.Format("You are over 1 year old. Your age is {0:0} months", DateDiff(DateInterval.Month, _birthdayDateTimePicker.Value, DateTime.Now))
        Else
            _ageLabel.Text = String.Format("You are over 2 years old. Your age is {0:0} years", age.TotalDays / 365.25)
        End If
    End Sub
End Class
and have a play.

I thinkl you may need to replace your developer if he is going to insist on silly basic things like ".net cannot do date math"

Please please please DO NOT store these values you calculate in a DB. Only the DOB should be stored and any ages should always be calculated. If you need to record how old a baby was when the record was made, keep 2 dates: birth date and record creation date, and subtract them. It's the most flexible way of storing the data
 

Attachments

  • ReBirth.zip
    13.7 KB · Views: 17
Well let me first say thanks for the quick reply, and secondly I just want to say that the developer didnt say it cannot do the math, but the way he can insert vb into the current project is limited to what they call "AutoFixs", which is like a small template that can be run against the forms data as you click submit, but he cannot add in vb into the current project as he is like the 2nd line developer.. he does more customization of forms, but only at the gui level and not as much of the VB. So i ask asking for input that I might be able to put into one of these templates to run against the current form.

I am wondering if what anyone has said will work, as the form already exists and would already be populated with data in the DOB field... I need this template to say.. look at DOB, do the math, and set the other 2 fields correctly, or have it run 2 more templates to populate the other 2 fields based off the math.. its very frustrating.. but these are things i can add in manually myself if I can get them working properly to begin with.

Here is a snippet of one of these what I call templates I can run against the system after the form is populated.
VB.NET:
Incident.ClaimName1 = Incident.LastName1.ToUpper() + ", " + Incident.FirstName1.ToUpper() +" "+ Incident.MiddleInitial1.ToUpper();
Incident.SpecialAnalysis[50] = "N";
What this code does is pretty much take First and last names (2 fields) and turn it into lastname, firstname and then set a dropdown field to No. I need to make the above code fit into something like that.. is it possible?

Thanks again

stan
 
So it's not a matter of can't but won't.

I'm assuming you have something like Incident.DOB & Incident.RecordDate to work with? It's going to boil down to having 2 dates so you can determine the TimeSpan between them.
 
Though not called that, yes there is a DOB and a LossDate, which is when it is filed. And as for storing the calculation as cjard says above.. I have to store this calculation of age if it gets figured out.. its a state mandated thing.. the record is NEVER going to be changed.. its stored as is
 
You'll always be able to calculate this information from the DOB and LossDate on demand. Cjard is pointing out the smart/flexible way is to do this. State mandates tend to be...not smart.

Whether you're storing the difference or not and regardless of what your member fields are called it appears you can get to these dates. From there the method needed to determine your criteria is simple as cjard pointed out.

Whether you can add the method or whether you need to light a fire under a developer's *** depends on your how your department is structured.
 
the math is quite simple, but the means to apply it to the system we have is not such as i cannot create functions nor can the developer I work with as it isnt custom built solution for my work specifically.. its an adaptation for us built overtop of another major application they support.. they are not willing to add in a change like this for just 1 client since we are hte only ones needing this specific change

So i can probably do DateTime.Now - incident.DOB, but not sure how I can do the DateDiff of that at the same time to update it into a field.. and on top of that, i dont know if I can do the if/then statements.. i wont have access to the developer until tomorrow, but I'd like to have all the input I can get at thisp oint
 
I cant really advise you how to write your system because I've never seen it. If you can work all the code I gave you, into a template then you're in luck.

Read my code closely and work out what you have available and how it matches what I wrote

I needed 2 dates so I could subtract them. This line of code does it:

Dim age As TimeSpan = DateTime.Now - _birthdayDateTimePicker.Value

The two dates are bolded and italicised.. There is no problem doing this:
If (date2 - date1).TotalDays < 365.25
a = (date2 - date1).TotalDays


As to DateDiff; its a VB function so it might be available. If "if" is not available, maybe the function Iif(test, true, false) is available.
 
Last edited:

Latest posts

Back
Top