Hi
How can I calculate age from a given DOB?
Thanks
Regards 8 1557
"John" wrote:
Hi
How can I calculate age from a given DOB?
Thanks
Regards
I would use something akin to the following:
Sub Main()
Dim DOB As Date = New Date(1925, 8, 4) ' use your favorite date
Dim Today As Date = Date.Now
Dim age As Integer = Today.Year - DOB.Year
If (Today.Month < DOB.Month) Then age = age - 1
If (Today.Month = DOB.Month) And (Today.Day < DOB.Day) Then _
age = age - 1
Console.WriteLine("Age: " & age)
Console.ReadLine()
End Sub
Hope this helps...
>
=?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=
<Fa************@discussions.microsoft.comwrote in news:8968EFD2-14D5- 4A********************@microsoft.com:
I would use something akin to the following:
Sub Main()
Dim DOB As Date = New Date(1925, 8, 4) ' use your favorite
date
Dim Today As Date = Date.Now
Dim age As Integer = Today.Year - DOB.Year
If (Today.Month < DOB.Month) Then age = age - 1
If (Today.Month = DOB.Month) And (Today.Day < DOB.Day) Then _
age = age - 1
Console.WriteLine("Age: " & age)
Console.ReadLine()
End Sub
Hope this helps...
Can you just go Now.Subtract(DOB).Year?
-- sp**********@rogers.com (Do not e-mail)
"Spam Catcher" wrote:
Can you just go Now.Subtract(DOB).Year?
That was my first thought, but my TimeSpan object doesn't have a Year
property. :(
Family Tree Mike wrote:
"Spam Catcher" wrote:
>Can you just go Now.Subtract(DOB).Year?
That was my first thought, but my TimeSpan object doesn't have a Year
property. :(
Probably just as well, it wouldn't know how many years X number of days is
anyway. :(
If you want a one line version, and don't mind adding a boolean expression, you
could write
Dim age As Integer = Now.Year - DOB.Year + (New Date(Now.Year, DOB.Month,
DOB.Day) Now)
=?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=
<Fa************@discussions.microsoft.comwrote in news:0D3CEEB1-F499- 43********************@microsoft.com:
"Spam Catcher" wrote:
>Can you just go Now.Subtract(DOB).Year?
That was my first thought, but my TimeSpan object doesn't have a Year
property. :(
Ah you're right!
Stupid me.
-- sp**********@rogers.com (Do not e-mail)
You know, I was going to suggest DateDiff, but it behaves weirdly.
On Mar 9, 4:00 pm, "Steve Gerrard" <mynameh...@comcast.netwrote:
Family Tree Mike wrote:
"Spam Catcher" wrote:
Can you just go Now.Subtract(DOB).Year?
That was my first thought, but my TimeSpan object doesn't have a Year
property. :(
Probably just as well, it wouldn't know how many years X number of days is
anyway. :(
If you want a one line version, and don't mind adding a boolean expression, you
could write
Dim age As Integer = Now.Year - DOB.Year + (New Date(Now.Year, DOB.Month,
DOB.Day) Now)
And this compiles with option strict on? It makes no sense to add a
boolean to an integer!
Chris
Chris Dunaway wrote:
On Mar 9, 4:00 pm, "Steve Gerrard" <mynameh...@comcast.netwrote:
>If you want a one line version, and don't mind adding a boolean expression, you could write
Dim age As Integer = Now.Year - DOB.Year + (New Date(Now.Year, DOB.Month, DOB.Day) Now)
And this compiles with option strict on? It makes no sense to add a
boolean to an integer!
For option strict, you would need
Dim age As Integer = Now.Year - DOB.Year + CInt(New Date(Now.Year,
DOB.Month, DOB.Day) Now)
I didn't say I would go about adding booleans to integers, only that you could
if you wanted it all in one expression.;-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ron Adam |
last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone
here for a great programming language.
Below is my first Python program (not my first program) and I'd
apreciate any...
|
by: Kasp |
last post by:
Hi there,
I am trying to make an OLAP cube on a table having two columns (datetime,
Number_of_times_an_event_occured).
My dimension is time and I want to measure the Min and Max times an event...
|
by: Joe Bongiardina |
last post by:
What does the message "calculating...." mean in the lower left status area
of a form?
I have a form with no calculated, concatenated or lookup fields, yet it
displays this msg.
The form takes...
|
by: jlm |
last post by:
I have a form which feeds table (TblEmpLeave) of Employee Leave Time
(time taken off for Administrative, Annual, Sick, Compensation leave).
I have EmpID, LeaveDate, LeaveType, LeaveHours fields on...
|
by: robin9876 |
last post by:
In an Access 2000 database on some forms 'Calculating...' is
continuously displayed in the status bar window and the text of the
control is automatically selected.
The only workaround is switching...
|
by: sugaray |
last post by:
Hi, my problem with calculating the size of an array is when
I pass an array as a parameter to a function which perform the
calculation, the result never comes right, like below:
int...
|
by: Umesh |
last post by:
i want to calculate the time required to execute a program. Also i
want to calcute the time remaining for the execution of the program.
how can i do that?
pl mention some good websites for...
|
by: laredotornado |
last post by:
Hi,
Can anyone recommend a free script for calculating UPS shipping? I am
familiar with the script written in 2000 by Jason Costomiris, but UPS
is using an XML interface and I wondered if...
|
by: =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= |
last post by:
Say I have a class like,
class Sample
{
public decimal first = 10;
public decimal second = 20;
}
I have initialized it
|
by: sumit kale |
last post by:
Hi,
Can somebody help me resolve my problem ?
I am getting error when calculating total using unbound textfiled in subform.
I have a main form called purchase_register_master and a subform...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |