Template talk:Age in days

Active discussions

ExamplesEdit

{{age in days|month1=1|day1=1|year1=2006}} gives 5651

"{{age in days|2006|1|1}}" gives "5651" [1]

Barack Obama has been president for 4536 days and will finish his term in -3075 days

UsedEdit

This is a useful template that should get more wider use. It is especially useful for lists counting title reigns. Alex43223 Talk | Contribs | E-mail | C 00:34, 28 February 2007 (UTC)

Leap days?Edit

Does it count leap days and other such calendar mysteries? --Brandon Dilbeck 01:47, 15 March 2007 (UTC)

Yes. It should uses the Template:Gregorian serial date which should that into account (according to that template-page). /AB-me (chit-chat) 17:32, 19 March 2007 (UTC)
Okay. Phew. --Brandon Dilbeck 19:23, 19 March 2007 (UTC)

SandboxEdit

These two examples fail, because they do not name their arguments:

  • March 21, 2007 was Error: Need valid year, month, day days ago.
  • May 24, 2007 was Error: Need valid year, month, day days ago.

Try again with argument names:

  • March 21, 2007 was 5207 days ago.
  • May 24, 2007 was 5143 days ago.

ArgumentsEdit

Why does this template even ask for arguments? Other similar templates like {{age}} do not. --Arctic Gnome (talkcontribs) 21:28, 7 August 2007 (UTC)

You mean argument names? I added the option of using unnamed parameters:

  • "{{age in days|2007|3|21}}" gives "5207" [2]
  • "{{age in days|2007|5|24}}" gives "5143" [3]
  • {{age in days|2007|5|24|2008|4|23}} gives 335

Patrick 13:40, 18 August 2007 (UTC)

InterwikiEdit

Please add [[de:Vorlage:Tagesdifferenz]].--Tilla2501 12:55, 18 August 2007 (UTC)

IWEdit

Please add no:Mal:Alder i dager. Nsaa 21:14, 26 September 2007 (UTC)

SeperatorsEdit

Could the template be modified to insert seperators into a search outcome (eg 3,258 rather than 3258)? --GW_SimulationsUser Page | Talk 15:41, 22 October 2007 (UTC)

DocumentationEdit

{{editprotected}}
Please use {{documentation}}. 16@r (talk) 03:02, 29 January 2008 (UTC)

 Y Done - Nihiltres{t.l} 19:09, 30 January 2008 (UTC)

Make this sort betterEdit

Can any template-writers figure this puzzle out for me? In sortable tables, numbers will sometimes be sorted by digit rather than by number, making it look like 20 is bigger than 100. I want to make this template add an invisible zero using the template {{0}} to the beginning of two-digit numbers, and two invisible zeros to the beginning of one digit numbers. In practise this fixes the sortable tables, but making it work with this template would take me quite a while of figuring. I think it can be done by coding that if RESULT is < 10, then print "{{0}}{{0}}RESULT" and if RESULT is < 100 then print "{{0}}RESULT". Another option to make it work with the tables is to somehow incorporate the template {{nts}} into it. Thanks --Arctic Gnome (talkcontribs) 05:36, 20 March 2008 (UTC)

In sandbox testing, just enclosing this template in {{nts}} seems to work. I was expecting (knock on wood) it to be much more complicated. --Arctic Gnome (talkcontribs) 05:52, 20 March 2008 (UTC)

Women in the United States SenateEdit

Hello,
I created a table showing length of services for different Senators. The problem I have is that for currently serving Senators I used the template {{Age in days nts}} which is supposed to sort correctly, but it doesn't. Any ideas? Victor Victoria (talk) 01:21, 27 August 2010 (UTC)

You are right to use Template:Age in days nts instead of Template:Age in days. But because it adds hidden zeroes and treats commas specially, it needs to be used in all the cells for the relevant column. At the moment, it is only present for those senators still serving, so they are sorting at the end of the list. Also, the commas in the wikitext for those senators who have served more than 999 days are causing the numbers to be treated as text (so that, say, 120 sorts between 12 and 13). Using {{Age in days nts}} throughout will fix this too, because it hides the commas from the sorting script. — Richardguk (talk) 03:43, 27 August 2010 (UTC)
I guess this problem has no fix at the moment. The same problem exists in List of United States Supreme Court Justices by time in office. Victor Victoria (talk) 03:58, 27 August 2010 (UTC)
You seem to misunderstand me. The fix does exist: simply replace the number of days (for those senators no longer serving) with {{Age in days nts|year1|month1|day1|year2|month2|day2}} where month1/day1/year1 is the start date and month2/day2/year2 is the end date (you might possibly need to adjust day2 by 1 in each case, depending on whether the end date has been counted as well as the start date). Once every row is using {{Age in days nts}} in the "days" column, it will sort properly. The same fix will work for the table in the Supreme Court Justices article. — Richardguk (talk) 05:29, 27 August 2010 (UTC)
Thanks for your help — it worked just like you promised. I'll fix the List of United States Supreme Court Justices by time in office later when I get some time. Victor Victoria (talk) 12:26, 27 August 2010 (UTC)
Using Template:Age in days nts needlessly adds load time for senators that are retired. You can instead use the number in the simple Template:NTS. —Arctic Gnome (talkcontribs) 20:51, 3 September 2010 (UTC)

Suggestion: handle BCE datesEdit

Summary: extend this template to handle dates before Common Era.

Description: {{Gregorian serial date}} throws an error for BCE dates and so makes this template unusable if either of the two ends of the interval is BCE. As a side-effect, {{Age in years and days}} cannot handle BCE intervals and some (rare) intervals that span the BCE/CE boundary.

Suggestion: Use {{JULIANDAY}} if any of the two ends of the interval is BCE, {{Gregorian serial date}} otherwise (as currently). Specify BCE dates using astronomical year numbering. {{JULIANDAY}}, unlike {{JD}}, uses the proleptic Gregorian calendar, and is thus equivalent to {{Gregorian serial date}} for measuring time intervals.

Proposed new template: {{User:Miranche/Miranche Age in days}}.

Test cases: User:Miranche/Template Age in days testcases.

Thoughts? – Miranche T C 01:32, 4 February 2012 (UTC)

Module:AgeEdit

I created Module:Age to fix some problems reported with {{Age in years and months}}, then experimented by adding some code to implement {{Age in days}} and {{Gregorian serial date}}. I do not know if this template has any performance issues, but if wanted, it could be replaced with the module. More information is at Module talk:Age. Johnuniq (talk) 10:04, 2 April 2013 (UTC)

New stuffEdit

Inputting full datesEdit

Code has been adjusted to allow for full dates to be input as parameters 1 and 2.

e.g. {{age in days|12 Mar 2000|27 Feb 2010}} → 3,639

Jimp 08:44, 10 April 2015 (UTC)

SortingEdit

|sortable=on will sort according to the number of seconds (using the SI unit for consistency across various template, e.g. {{val}}). This will make {{age in days nts}} redundant. Jimp 08:44, 10 April 2015 (UTC)

FormattingEdit

The template did not format numbers correctly. Numbers were not delimited and negative numbers were output with a hyphen instead of a negative sign. This formatting is good if the number is to be used for further calculations; however it is bad for display in articles. Of course, for numbers between 0 and 999 inclusive, this is unimportant, but outside of this range, it's problematic. Two new formatting options have been added: |format=commas will give true minus signs and add commas as per {{formatnum:}} and |format=gaps will give true minus signs and add thin spaces as per {{val}} whilst |format=raw will produce the unformatted numbers with hyphens for minus signs as has been used in the past. Note that for year, month and day input the default is still the raw form (this template is used by others); however, for full-date input the default is commas (the most commonly used formatting on WP). Jimp 08:44, 10 April 2015 (UTC)

Displaying the unitEdit

Editors may not know whether the number of days will be one or not. How do you pluralise in this case? |show unit=full sorts this out by giving "day" or "days" as appropriate. |show unit=abbr gives an abbreviation, "d". The default is still not to give units. Jimp 08:44, 10 April 2015 (UTC)

Unexpected number error: spaces cause error messageEdit

Note that a space before the "2" (in the last parameter) causes an error. Whitespace should be trimmed. – Wbm1058 (talk) 23:20, 13 February 2016 (UTC)

  • {{age in days|{{#ifexpr:03<02|{{#expr:2008-1}}|{{#ifexpr:03=02|{{#ifexpr: 2<27|{{#expr:2008-1}}|2008}}|2008}}}}|02|27|2008|03| 2}}
  • 4
  • {{age in days|{{#ifexpr:03<02|{{#expr:2008-1}}|{{#ifexpr:03=02|{{#ifexpr: 2<27|{{#expr:2008-1}}|2008}}|2008}}}}|02|27|2008|03|2}}
  • 4
Another example
  • −53

I forgot why I'm watching this page so I looked above and found I wrote a module which I can barely remember, but according to my confident statements at Module talk:Age, the module is ready to replace this template, if wanted. Using the test "template" {{User:Johnuniq/age days}} instead of the above shows that it works for each of those, producing 4, 4, and −182. I'm busy elsewhere and it may be a few days before I get a chance to look at the module to work out its state, but it probably is ready. Johnuniq (talk) 01:24, 14 February 2016 (UTC)

Proposed generic template time intervalEdit

Thanks for your efforts Johnuniq. If your module is going to replace the date and age templates, what I'd like to see is a way to express durations between two time points at any level of precision, e.g. today I want to add the amount of time that a cargo supply mission has remained docked to the ISS but the age templates are limited to showing days; we need to show this with days + hours and minutes. Some other cases may need to compute years and months for long durations or months and days for shorter ones, and the only kludge we have here is {{age for infant}} which has arbitrary boundaries for the precision to display. There is a {{duration}} template but it only formats a given duration and it has been created with the special purpose of documenting lengths of music pieces. Ideally we would have something along the lines of your {{convert}} with relevant formatting options available and reasonable defaults for most-used cases. Example syntax I'd like:

Code Display Notes
{{time interval | 1958-06-07 | 2016-04-21 }} 57 years most generic form, can be used for a person's age, time between events, lengths of eras, etc.
{{time interval | 1961 | 1989 }} 28 years lower precision input works too
{{time interval | 1989-08-15 }} 31 years second date omitted, defaults to now
{{time interval | 15 August 1989 }} 31 years also accept spelled-out date formats
{{time interval | 15 August 1989 | disp=raw }} 31 no units, display years elapsed as number only
{{time interval | 1958-06-07 | 2016-04-21 | disp=age }} 57 years old traditional age display
{{time interval | 1794-06-08 | 1795-03-16 | disp=age }} 9 months 8 days defaulting to {{age_for_infant}} precision for ages under 3
{{time interval | 2016-04-08 20:43 | 2016-05-11 18:31 }} 32 days 21 hours 48 minutes precise duration
{{time interval | 2016-04-08 20:43 | 2016-05-11 18:31 | abbr=on }} 32d 21h 48m abbreviate units
{{time interval | 2016-04-08 20:43 | 2016-05-11 18:31 | round=hours }} 32 days 22 hours round to closest hour
{{time interval | 2016-04-08 20:43 | 2016-05-11 18:31 | round=days }} 33 days round to closest day
{{time interval | 28 July 1914 | 11 November 1918 | round=weeks }} 4 years, 3 months and 2 weeks Replacing {{age in years, months, weeks and days}} (example from World War I)

With this, I believe that all the current age-related templates could be rewritten as syntactic sugar based on the generic {{time interval}}, so we would have a painless transition from legacy syntax. Looking forward to your feedback + input from other editors. Let's get this done! — JFG talk 05:56, 13 May 2016 (UTC)

The good news is that Module:Date has the ability to parse the date/time examples above, and can easily supply date differences in years, months, days, hours, minutes, seconds, and can supply weeks as well. It's only limitation is that each date has to be fully specified, and valid. It works from 9999 BCE to 9999 CE and accepts varieties like 24-hour time or "am" or "a.m.", and "AD", "CE", etc. The less good news is that I'm busy on another project and am unlikely to return to this topic for a couple of weeks. The syntax above looks good and should be no problem. Johnuniq (talk) 07:33, 13 May 2016 (UTC)
Your new Module:Date looks like well-rounded code, thanks! I have just put together a first version of {{time interval}} to see how this could work; it uses a new Module:Time interval which invokes Module:Date in turn. You can see test cases at Template:Time interval/testcases. The module can only display time interval in years for now, I will extend it to the other cases when I have more time. The test case 1961 to 1999 renders nil, possibly because Module:Date doesn't interpret the "1961" raw string as a year; would you like to change this or should I handle it in the Time interval module? — JFG talk 13:37, 13 May 2016 (UTC)
Good progress. I just put what I've been working on in Module:Age/sandbox. That is Module:Age with modifications to use Module:Date. My energy went into Date, and Age is not ready for the light of day, but I thought I would post it to show my plans. I haven't really looked yet, but currently do not see why Module:Time interval is needed—why not just stick to Module:Age?
Re your question, here are my to do notes on that (this mentions {{hla}} = "how long ago"):
age.lua needs a way to handle partial (ambiguous/incomplete) dates.
For {{hla}}, from_date can omit any component.

Perhaps change:
    get_dates(frame, want_mixture)
    get_dates(frame, want_mixture, want_partial)
and have a parameter to Date to tell it that partial is ok, in which
case it should return a simple table of form:
    { year = x, month = y, day = z, incomplete = true }
where any or all components may be missing.
If any specified components are invalid, return nil.

The simple table might be not-so-simple with a metatable
to get the oldest or newest valid dates:
    oldest_date
        if year == nil, return nil
        if month == nil, month = 1
        if day == nil, day = 1
        return Date(year, month, day)
    newest_date
        if year == nil, return nil
        if month == nil, month = 12
        if day == nil, day = days_in_month(year, month)
        return Date(year, month, day)

Partial dates are assumed to be Gregorian dates.
I'll need some quality time to think about that! Johnuniq (talk) 00:58, 14 May 2016 (UTC)
I see what you are trying to do. In my experience, fuzzy dates are required e.g. when we have the year and no date, or the minutes and no seconds. The "strange mixtures" you mention in the doc, e.g. having a year and a day but no month in between, are not worth supporting; they must be coming from limitations of the template processor and syntax, as I can't imagine a genuine need for guessing an intermediate value between a more precise and a less precise one. To cover most cases elegantly I would suggest associating a precision attribute to each Date object, so that calculations can always do the right thing. Example: a historic character was born in 1542 and died on December 12, 1598: the birth date has precision one year and the death date has precision one day; if we compute their difference to find his age at death, we can only state the lower precision, i.e. estimate his age to 56 years. The precision of a date also drives how it can be displayed (don't show any numbers which are below the precision, also think of "circa 1542"). This approach would solve one of my test cases computing the age of the Berlin Wall from 1961 to 1989 (because neither the start date nor the end date can be precisely assessed, however the years are well established): you need to parse "1961" as "year=1961, month=7, day=1, precision=year" (specifying the unknown date to July 1st so that calculations of time differences use the middle point of the year as reference). If you're feeling adventurous, I'd suggest intermediate precisions such as quarter or decade so we can parse "Q3, 2009" and "1970s", but let's start by getting the simple years right! — JFG talk 05:29, 16 May 2016 (UTC)
@Johnuniq and JFG: I'm extremely happy to see this being worked on, for space mission duration uses that JFG mentions, and wonder when Module:Date will be ready for release. John, just out of curiosity, what is the reason for a Date template and Age template? And I agree, there seems no reason to have a separate Time Interval template if Date will perform the same function. Huntster (t @ c) 03:12, 16 May 2016 (UTC)
I wrote Module:Age to fix a problem with a template that someone requested. Later I noticed other reports of minor issues with other templates, and decided to write Module:Date to hold all the date functions, and then replace Module:Age with code to implement the various templates. Module:Age/sandbox is where I'm up to, while Module:Date is pretty well finished. I say "pretty well" because I may add features needed to conveniently have Module:Age handle a variety of templates. In summary: Module:Date will never be directly used by a template, while Module:Age will handle templates and will use Module:Date to do the date calculations. Module:Date has been extensively tested, while Module:Age remains on my to do list. Johnuniq (talk) 03:31, 16 May 2016 (UTC)
@Johnuniq: Thanks for that. Well, just know that people are excited at the prospect of a unified date handling template. I plan to deploy the finished product across a very wide variety of spaceflight articles to replace the various "Age in..." templates when it becomes available, especially for the ISS missions since hours and minutes will be available (wooohooo!). Huntster (t @ c) 04:10, 16 May 2016 (UTC)
Glad you like it, Huntster! Now we need to agree on syntax and packaging. As Johnuniq explained, Module:Date is a collection of date parsing, calculation and regurgitation features, not intended for direct use. Then there is the new Module:Age which is designed to emulate all the legacy age templates for backward compatibility. Then Module:Time interval intends to provide easier and more generic date calculation and formatting. Both Age and Time interval are works in progress, so we might decide to merge them and keep only one. However I would argue that psychologically Age is biased towards living beings and long durations whereas Time interval can apply to shorter periods and abstract ideas (duration of a spacewalk, period of a comet, length of an era, …). Of course a single module could provide many methods to cover all bases. I have suggested some syntax for {t|time interval}} and started implementing it. The main difference I see between the Age and Time interval concepts now is that Age is geared towards dates provided with 3 separate parameters as in {{age|year1|month1|day1|year2|month2|day2}} whereas Time interval works with full dates, either in literal {{time interval | March 12, 1999 | September 15, 2008}} or ISO {{time interval | 1999-03-12 | 2008-09-15}} format. When we add time to the mix, parameter passing becomes unwieldy and I'm convinced that most editors would prefer typing literal dates in natural format, including hours and minutes if needed, rather than split everything with pipe characters; the encyclopedia would be easier to maintain. (A simple example that bugs me everyday, {{as of}} doesn't accept natural dates, which are exactly what we want in the text where this template gets used.) — JFG talk 05:29, 16 May 2016 (UTC)
Can't wait to get rid of such horrors, although amazingly they do the job! — JFG talk 05:58, 16 May 2016 (UTC)
<includeonly>{{end-date
|dt = {{{dt|}}}
|class-extra = dday deathdate
|{{{gregorian|{{{1|}}} }}}
|{{{3|{{{1|}}}}}}}} (aged {{age|{{#ifeq:"{{lc:{{{2|0009-11}}}}}"|"{{Four digit|{{#expr:{{{2|0009-11}}}}}}}"|<!--Here if it is a 4 digit year only-Test1 satisfied: see talk -->{{{2|0009-11}}}|{{#expr: {{#iferror:{{#ifexpr:((abs({{{2|0009-11}}}))< 1900) and  ({{#time:Y|{{{2|0009-11}}}}} >1900)  | {{#ifexpr:({{#time:Y|{{{2|0009-11}}}}}) <2000|{{#expr:{{#time:Y|{{{2|0009-11}}}}}-1900}}|{{#expr:{{#time:Y|{{{2|0009-11}}}}}-2000}} }} |{{#time:Y|{{{2|0009-11}}}}} }}|{{#time:Y|{{{2|0009-11}}}}} }}{{#switch:{{{bce|}}}|b|d|bd|db=*(-1) +1}}}} }}|{{#time:m|{{{2|}}}}}|{{#time:d|{{{2|}}}}}|{{#ifeq:"{{lc:{{{1|0009-11}}}}}"|"{{Four digit|{{#expr:{{{1|0009-11}}}}}}}"|<!--Here if it is a 4 digit year only-Test1 satisfied: see talk -->{{{1|0009-11}}}|{{#expr: {{#iferror:{{#ifexpr:((abs({{{1|0009-11}}}))< 1900) and  ({{#time:Y|{{{1|0009-11}}}}} >1900)  | {{#ifexpr:({{#time:Y|{{{1|0009-11}}}}}) <2000|{{#expr:{{#time:Y|{{{1|0009-11}}}}}-1900}}|{{#expr:{{#time:Y|{{{1|0009-11}}}}}-2000}} }} |{{#time:Y|{{{1|0009-11}}}}} }}|{{#time:Y|{{{1|0009-11}}}}} }}{{#switch:{{{bce|}}}|bd|d|db=*(-1) +1}}}} }}|{{#time:m|{{{1|}}}}}|{{#time:d|{{{1|}}}}} }})</includeonly><noinclude>
{{documentation}}
</noinclude>

Mediawiki wizards, circa 2009

Please see Template talk:Time interval#Proposed syntax for a demonstration of the new system which achieves most of the above. Johnuniq (talk) 10:51, 6 June 2016 (UTC)

Module:Age testsEdit

I'm trying to increase the consistency of some of the age templates by using Module:Age. The main motivation is so sorting with the nts templates such as {{age in days nts}} will be consistent with other age templates such as {{age in years nts}}.

A preliminary test is at Template:Age in days/testcases2 which uses the tests from Template:Age in days/testcases but uses a system that can automatically check the results. {{age in days/sandbox}} uses the module and its results are compared with those from {{age in days}} at Template talk:Age in days/testcases2. Currently that is showing hundreds of fails due to differences in the wikitext produced. I can't see any substantive differences and will investigate it further. I'm putting this note here for anyone interested but also as a reminder to myself about where I put the tests. Johnuniq (talk) 10:04, 30 December 2017 (UTC)

After doing some search-and-replace changes to the tests for expected differences, the test results show that {{age in days/sandbox}} agrees with {{age in days}}. Johnuniq (talk) 04:43, 2 January 2018 (UTC)

Something is wrongEdit

Should {{age in days|19 Aug 2008|4 Sep 2010}} give \? That's what it's currently giving. Uglemat (talk) 09:42, 22 February 2018 (UTC)

Hmm, so it does:
  • {{age in days|19 Aug 2008|4 Sep 2010}} → 746
  • {{age in days/sandbox|19 Aug 2008|4 Sep 2010}} → 746
I included {{age in days/sandbox}} to show that it works correctly. The sandbox template uses Module:Age and I need to do some more checking before switching the main template to use the sandbox code. The main problem with such a change is that the module gives an error if dates are not valid. That is good, but it might mean that several errors occur in articles until they are cleaned. I guess you could use the sandbox where needed and it could be changed back to the main template in due course. Johnuniq (talk) 09:51, 22 February 2018 (UTC)
I just noticed the previous section. Apparently I thought the sandbox was good to go in early January. I'll think about it soon. Johnuniq (talk) 09:52, 22 February 2018 (UTC)
The problem was due to some vandalism at Template:Age in days/sec which I reverted, so it is good now. However, I am planning to use the module soon. Johnuniq (talk) 09:41, 23 February 2018 (UTC)

Calculation ProblemEdit

We need a template to be able to count days which includes the first day as day one for when calculating lifespans because calculating the days between the 2 dates ignores that first day, a persons birthday is not the last day of the year it is the first day of his next year, a person born on January 1st hits his 365th day of life on December 31 not on the next January 1st. SCAH (talk) 17:20, 22 March 2019 (UTC)

Suppose someone was born at 12 noon on Monday 1 January 2018. At 12 noon on Thursday 4 January 2018, they were exactly three days old. Consider:
  • {{age in days|1 Jan 2018|4 Jan 2018}} → 3
  • {{age in days|1 Jan 2018|4 Jan 2018|duration=on}} → 4
  • {{duration in days|1 Jan 2018|4 Jan 2018}} → 4
The duration option is for scenarios such as a conference which started at 9:00 am on 1 January 2018 and finished at 5:00 pm on 4 January 2018. In that case, the final day is counted which adds 1. Johnuniq (talk) 23:20, 22 March 2019 (UTC)
Return to "Age in days" page.