Birthday stuff

I

isabelle

thank you joeu2004, this last one returns a positive number, and sorry for "jj-mm-aa"

="There are "&TEXT(DATE(YEAR(TODAY()),MONTH(DOB),DAY(DOB))-TODAY(),"0"" days""")&
" before Joe ("&TEXT(DOB,"mmm-dd-yyyy")&") becomes "&TEXT((1900-YEAR(TODAY()-DOB+DATE(1,0,0)))*-1,"0")&" years old"
 
R

Ron Rosenfeld

And I also need to fix the original 'math' as well, no?

Yes, your original has a potentially serious problem.

Given the following data:

DOB: 25 Dec 2009
Today's Date: 10 Jan 2012

In versions of Excel starting with, I think, Excel 2007 SP1, your formula will give a result of 2 years, 0 months, and 129 days instead of 2 Years, 0 Months, 16 days.

Also, with regard to leaplings, your formula makes the assumption that in a common year, their birthday will be on Mar 1. While this is true in some locales, it is probably more common that a leaplings birthday will be celebrated on Feb 28.

I would suggest either just reporting the age in years, or using a User Defined Function to return the string in Years, Months and days.

The following UDF should work, with the caveats concerning leaplings. This does assume Feb 28 for a leapling's birthday in a common year.

To enter this User Defined Function (UDF), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this User Defined Function (UDF), enter a formula like

=DateIntvl(DOB,TODAY())

in some cell or concatenated in with your formula

=CONCATENATE(Birthname," is ",dateintvl(DOB,TODAY()))

===========================
Option Explicit
Function DateIntvl(d1 As Date, d2 As Date) As String
'Note that if d1 = 29 Feb, the definition of a year
'may not be the same as the legal definition in a
'particular locale
'Some US states, for some purposes, declare a
'leapling's birthday on 1 Mar in common years; England
'and Taiwan declare it on Feb 28
Dim temp As Date
Dim i As Double
Dim yr As Long, mnth As Long, dy As Long
Dim sOutput() As String

Do Until temp > d2
i = i + 1
temp = DateAdd("m", i, d1)
Loop

i = i - 1
temp = DateAdd("m", i, d1)

yr = Int(i / 12)
mnth = i Mod 12
dy = d2 - temp

ReDim sOutput(0 To -(yr > 0) - (mnth > 0) - (dy > 0) - 1)
i = 0
If yr > 0 Then
sOutput(i) = yr & IIf(yr = 1, " Year", " Years")
i = i + 1
End If
If mnth > 0 Then
sOutput(i) = mnth & IIf(mnth = 1, " Month", " Months")
i = i + 1
End If
If dy > 0 Then sOutput(i) = dy & IIf(dy = 1, " Day", " Days")

DateIntvl = Join(sOutput, ", ")

End Function
==============================
 
J

joeu2004

thank you joeu2004, this last one returns a positive number [....]
="There are  "
&TEXT(DATE(YEAR(TODAY()),MONTH(DOB),DAY(DOB))-TODAY(),"0"" days""")
&" before Joe ("&TEXT(DOB,"mmm-dd-yyyy")&") becomes "
&TEXT((1900-YEAR(TODAY()-DOB+DATE(1,0,0)))*-1,"0")&" years old"

Not on my computer ;-). If TODAY() returns May 21 2011, try typing
May 20 1949 or any earlier day in that year into DOB.
 
S

SoothSayer

Yes, your original has a potentially serious problem.
snip (my service will not allow your non-proper line lengths, so I have
to snip 'em. (but I still have them)



Wow, that is a lot of code. Thanks for that.

And Excel will not author nor incorporate any proper embedded baseline
function update for this?

Or is this the "our year starts on" and "their year starts on..." thing
that messes up 'week-of-year' counts?

One would think there would be a date handling engine within office on
the whole that the user or group sets up according to their needs,
region, etc.

Without custom coding constantly.

That, or we should be able to put functions up on the ribbon, and NOT
have a workbook be explicitly referred to as having a 'macro' within it.

OR, the person would have to DL and ADD those components before that
workbook would properly function.

This has to do with international differences doesn't it?

How sad that we get handcuffed because the source code would
inordinately bloat if they put in stronger date handling routines and
selections for us.

EA games makes reality happen on the screen in front of you, and they
don't charge several hundred dollars a copy for it, and then charge for
'support' as well.

With all the money MS has they could incorporate a better date handling
engine.

So much for my rant.

Thanks for the code segments and deep lesson in just how much was left
OUT of the base office package.

Does the "Access" database allow one better date handling?

How can this be such an overlooked segment of modern office computing
after all these years?

You MS guys are lagging. AND passing the buck off onto not previously
needed but now needed script programmers.

So we should say "Thanks for the office automation products...", and
"Get on the stick with making them right, dag nabbit!".
 
S

SoothSayer

thank you joeu2004, this last one returns a positive number [....]
="There are  "
&TEXT(DATE(YEAR(TODAY()),MONTH(DOB),DAY(DOB))-TODAY(),"0"" days""")
&" before Joe ("&TEXT(DOB,"mmm-dd-yyyy")&") becomes "
&TEXT((1900-YEAR(TODAY()-DOB+DATE(1,0,0)))*-1,"0")&" years old"

Not on my computer ;-). If TODAY() returns May 21 2011, try typing
May 20 1949 or any earlier day in that year into DOB.

Yes. I assumed it was obvious that DOB and BirthName were 'named
ranges'. I put info into a cell location and name it quite often as it
makes formulas easier (shorter), but not necessarily for a third party to
read or comprehend.

I should have framed the original question a bit better too I suppose.
 
R

Ron Rosenfeld

snip (my service will not allow your non-proper line lengths, so I have
to snip 'em. (but I still have them)



Wow, that is a lot of code. Thanks for that.

Glad to help.

With all the money MS has they could incorporate a better date handling
engine.

So much for my rant.

Thanks for the code segments and deep lesson in just how much was left
OUT of the base office package.

You're welcome.

Does the "Access" database allow one better date handling?


I don't know. I don't use Access.

How can this be such an overlooked segment of modern office computing
after all these years?

You MS guys are lagging. AND passing the buck off onto not previously
needed but now needed script programmers.

You should direct your suggestions for improvements to Microsoft. But you'll have to search for where to post it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top