473,769 Members | 5,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculate an age

Hi all,

I have searched in the standard distribution if there was a function
to return the difference between 2 dates expressed like an age :
number of years, of months and days. The difference between datetime
instances returns a timedelta object that gives a number of days, but
not an age

So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task

Regards,
Pierre
Dec 6 '07 #1
9 7903
On Dec 7, 8:34 am, Pierre Quentel <quentel.pie... @wanadoo.frwrot e:
Hi all,

I have searched in the standard distribution if there was a function
to return the difference between 2 dates expressed like an age :
number of years, of months and days. The difference between datetime
instances returns a timedelta object that gives a number of days, but
not an age

So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task
and a rather usually imprecisely specified task [what do you mean by
"number of months"?] with multiple interpretations/implementations/
doctrines the publication of any one of which attracts a truckload of
rotten tomatoes and derision from adherents of other sects :-)
Dec 6 '07 #2
On Dec 6, 4:19 pm, John Machin <sjmac...@lexic on.netwrote:
On Dec 7, 8:34 am, Pierre Quentel <quentel.pie... @wanadoo.frwrot e:
Hi all,
I have searched in the standard distribution if there was a function
to return the difference between 2 dates expressed like an age :
number of years, of months and days. The difference between datetime
instances returns a timedelta object that gives a number of days, but
not an age
So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task

and a rather usually imprecisely specified task [what do you mean by
"number of months"?] with multiple interpretations/implementations/
doctrines the publication of any one of which attracts a truckload of
rotten tomatoes and derision from adherents of other sects :-)
I think metric months are all the same length, 10**1.483408978 5587095
days.

-- Paul
Dec 6 '07 #3
On Dec 6, 11:19 pm, John Machin <sjmac...@lexic on.netwrote:
On Dec 7, 8:34 am, Pierre Quentel <quentel.pie... @wanadoo.frwrot e:
Hi all,
I have searched in the standard distribution if there was a function
to return the difference between 2 dates expressed like an age :
number of years, of months and days. The difference between datetime
instances returns a timedelta object that gives a number of days, but
not an age
So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task

and a rather usually imprecisely specified task [what do you mean by
"number of months"?] with multiple interpretations/implementations/
doctrines the publication of any one of which attracts a truckload of
rotten tomatoes and derision from adherents of other sects :-)
It may be imprecisely specified, yet it's quite useful anyway. I've
got an implementation at http://blog.tkbe.org/archive/python-how-old-are-you/
if anyone's interested..

-- bjorn
Dec 7 '07 #4
On Dec 7, 7:09 pm, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
How many days in a year? 365.25 (J2000 epoch), 365.2422 [as I
recall](B1900 epoch), 365.0 (non-leap year), 366 (leap year)? Gregorian
or Julian calendar -- and depending upon one's country, the Gregorian
reform may take place at different years.

Simple months of (year/12) days, or calendrical mishmash (30 days
hath September, April, June, and November...) again with leap year
exceptions?
Hi,

I don't see where the ambiguity is. Isn't it obvious what we mean by
"I am X years, Y months and Z days" ?

Regards,
Pierre
Dec 8 '07 #5
On Fri, 07 Dec 2007 23:37:23 -0800, Pierre Quentel wrote:
On Dec 7, 7:09 pm, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
> How many days in a year? 365.25 (J2000 epoch), 365.2422 [as I
recall](B1900 epoch), 365.0 (non-leap year), 366 (leap year)? Gregorian
or Julian calendar -- and depending upon one's country, the Gregorian
reform may take place at different years.

Simple months of (year/12) days, or calendrical mishmash (30 days
hath September, April, June, and November...) again with leap year
exceptions?

I don't see where the ambiguity is. Isn't it obvious what we mean by
"I am X years, Y months and Z days" ?
That's obvious but given either the present date or the birth date along
with that information it's not so clear what the other date may be.
Unless you give the info about the used calender systems and the points in
time (according to which calender system!?) when to use which system.

If you are just asking those questions for people living now (and are
not called Connor McLeod ;-) and the gregorian calender it's easy but
providing functions in the standard library for arbitrary date calculation
involving years is not so easy.

Ciao,
Marc 'BlackJack' Rintsch
Dec 8 '07 #6
What is so obvious about dealing with months that vary in length and the
leap-year issue? Nothing. If you were born on a day that does not
exist every year (Feb 29th), how old are you on Feb 28th? or Mar 1 of
non-leap years? If you were born on Feb 29th, then you would be one
month old on March 29th, but would you be one year, one month and one
day old on March 29th of the next year? or would you merely be one year
and one month old? I believe this is exactly why datetime merely states
deltas in days, not months or years.
Marc 'BlackJack' Rintsch wrote:
On Fri, 07 Dec 2007 23:37:23 -0800, Pierre Quentel wrote:

>On Dec 7, 7:09 pm, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:

>> How many days in a year? 365.25 (J2000 epoch), 365.2422 [as I
recall](B1900 epoch), 365.0 (non-leap year), 366 (leap year)? Gregorian
or Julian calendar -- and depending upon one's country, the Gregorian
reform may take place at different years.

Simple months of (year/12) days, or calendrical mishmash (30 days
hath September, April, June, and November...) again with leap year
exceptions?

I don't see where the ambiguity is. Isn't it obvious what we mean by
"I am X years, Y months and Z days" ?

That's obvious but given either the present date or the birth date along
with that information it's not so clear what the other date may be.
Unless you give the info about the used calender systems and the pointsin
time (according to which calender system!?) when to use which system.

If you are just asking those questions for people living now (and are
not called Connor McLeod ;-) and the gregorian calender it's easy but
providing functions in the standard library for arbitrary date calculation
involving years is not so easy.

Ciao,
Marc 'BlackJack' Rintsch

--
Shane Geiger
IT Director
National Council on Economic Education
sg*****@ncee.ne t | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHWl4YyuP 8LzpNs84RAtzmAJ 4vDeb6AkiR04rkD y0iEfXuHixPrQCf YJw3
hlyZd7Z/6aiQprbbIPyB29M =
=5sXX
-----END PGP SIGNATURE-----

Dec 8 '07 #7
On Dec 8, 10:04 am, Shane Geiger <sgei...@ncee.n etwrote:
What is so obvious about dealing with months that vary in length and the
leap-year issue? Nothing. If you were born on a day that does not
exist every year (Feb 29th), how old are you on Feb 28th?
X years, 11 months, 28 days

or Mar 1 of
non-leap years?
X' years, 0 month, 1 day

If you were born on Feb 29th, then you would be one
month old on March 29th, but would you be one year, one month and one
day old on March 29th of the next year? or would you merely be one year
and one month old?
1 year, 1 month, 0 day ; why would there be one day more ? People born
on the 28th would be one year, one month and one day old. If two dates
have the same day-in-the-month then the difference is X years, Y
months and 0 day

I understand that there is no possible conversion from a number of
days to a (X,Y,Z) tuple of (years,months,d ays), and the reverse. But
the difference between 2 dates can be unambiguously expressed as
(X,Y,Z), and given a start date and an interval (X,Y,Z) you can also
find the end date unambiguously, provided the arguments are valid (for
instance, 1 month after the 30th of January is not valid)

Regards,
Pierre
Dec 8 '07 #8
En Sat, 08 Dec 2007 14:37:13 -0300, Pierre Quentel
<qu************ @wanadoo.frescr ibió:
I understand that there is no possible conversion from a number of
days to a (X,Y,Z) tuple of (years,months,d ays), and the reverse. But
the difference between 2 dates can be unambiguously expressed as
(X,Y,Z), and given a start date and an interval (X,Y,Z) you can also
find the end date unambiguously, provided the arguments are valid (for
instance, 1 month after the 30th of January is not valid)
As a side note, the "legal date reckoning" in Argentina considers that
case too: 1 month after the 30th of January is Feb 28 (or 29 on leap
years); 1 month after March 31 is April 30.

--
Gabriel Genellina

Dec 11 '07 #9
You might want to look at pyfdate: http://www.ferg.org/pyfdate

This Python program:
=============== =============== =============== =============== =============== ===
from pyfdate import *
birthday = Time(2000,2,29)

today = Time(2003,2,28)
years, months, period = today.diffym(bi rthday)
print "On", today.d
print "person is", years, "years", months,"months" , period.shortest

today = Time(2003,3,1)
years, months, period = today.diffym(bi rthday)
print "On", today.d
print "person is", years, "years", months,"months" , period.shortest
=============== =============== =============== =============== =============== ===

produces this output
=============== =============== =============== =============== =============== ===
On February 28, 2003
person is 3 years 0 months
On March 1, 2003
person is 3 years 0 months 1 day
=============== =============== =============== =============== =============== ===

Dec 18 '07 #10

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

Similar topics

2
4021
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum default is 4 letters). This is the Fed. Everything is a TLA (three-letter acronym). Therefore, since I'm building a PORTABLE web application, changing MySQL's default settings for fulltext index querying is completely undoable and unrealistic, so...
1
9993
by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a number. That number will appear in a seperate box at the bottom. So basically whatever you choose has a corresponding number associated with it (except for the text input, which you enter whatever number) and those numbers are added and produced in...
2
324
by: Gálos Zsuzsa | last post by:
Hi all, I need to calculate Formulas. For example: dim strFormula as string="25*(12-6)" I ned a DotNet Function to calculate this Formula (25*(12-6)=150): dim dblValue as double = 150
1
2691
by: Robert de Ridder | last post by:
I use an asp page to display pages, where the dynamic content is in an iframe. To calculate the height of the iframe I use the calcheight function. However when trying to do this with external pages, I get an access denied error, and the iframe won't display correctly. Is there a way to solve this or another way to calculate the height for the iframe. The relevant code displayed below. Thanks in advance for any help,
4
9341
by: Jan Szymczuk | last post by:
I'm creating an MS Access 2000 database where I have a number of people entered using simple basic fields, Surname: SMITH Forenames: John DoB: 09/09/1958 Age: (this needs to be automated to show years e.g. 46) I am trying to get the age to be automatically shown after a persons DoB (date of birth) is entered into the DoB field. I have tried using this formula in the Control Source of the Age field...
3
5962
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now calculate in the query the amount of weeks and days within the 17 days to show 2 weeks 3 days. I can create the function within excel, (A1 as cell with the days within it) as: =INT(A1/7) & " Weeks, " & MOD(A1,7) & " days" but cant seem to...
0
4641
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars (double) Sales Units (double) Promo (Text) -- is null or "X" AvgWklyDollars (double) AvgWklyUnits (double) I have a vba module which I thought would work, but it doesn't. I think the problem is an embedded SQL Totals Top 8 query, which doesn't...
6
4098
by: rrstudio2 | last post by:
I am using the following vba code to calculate the median of a table in MS Access: Public Function MedianOfRst(RstName As String, fldName As String) As Double 'This function will calculate the median of a recordset. The field must be a number value. Dim MedianTemp As Double Dim RstOrig As Recordset Set RstOrig = CurrentDb.OpenRecordset(RstName, dbOpenDynaset)
1
5116
by: mzovko20 | last post by:
Hello ! I´m having problem with this. I already created index.html document which allows user to input his/her date of birth. It looks like this : <html> <body> <center> <h3>How old are you ??</h3> <table border="0" width="25%"> <form action="calculate.php" method="get"> <td bgcolor="#FFCC00 ">Your name</td> <td><input type="text" name="name" maxlength="20" value="name"></td>
5
5911
by: Big P | last post by:
Hello, I would like to calculate cells in DataGridView ( VB Express) My datagridview1 looks something like this. --------------------------------------… Row# col1 col2 col3 Col 4 --------------------------------------… Row1 25 13 2 Row2 26 24 4
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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
9994
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
9863
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
8872
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...
0
5299
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
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.