Jump to content
TNG Community

Age less then 1 year


Adri1

Recommended Posts

Is there a solution or a mod to show the age of children who are younger then 1 year in Months, days....

At the moment it is 0 year.

Link to comment
Share on other sites

I guess by now, if nobody has replied with a mod, there might not be one. The system has a fairly complicated function for calculating age (e.g. what's shown in parentheses on getperson.php); over 160 lines in v13. The formula considers each format/field (birthdate, birthdatetr, deathdate, deathdatetr, albirthdate, altbirthdatetr) and if any are missing (e.g. someone is alive or missing data), whether "BEF"(ore), "AFT"(er) are used, handling bad data or inconsistent data, if a date has a day, month, or not, etc. - I think you get the idea. 

One option for a potential mod might be this: if both birthdatetr and deathdatetr (e.g. 1961-09-23) are present and don't have "00" for the month or day... THEN

Subtract the 2 dates and if the difference is 1) if more than 364 days, do nothing (use existing formula), 2) else show months and days. I guess you could either show "0 months, 14 days", or just "14 days", depending on preference (though the first is easier).

Writing the code to insert into the age function in globallib.php would not be very difficult, but creating a packaged mod would be something else...

Thoughts?

 

GOGGS

Link to comment
Share on other sites

21 minutes ago, GOGGS said:

Writing the code to insert into the age function in globallib.php would not be very difficult, but creating a packaged mod would be something else...

@GOGGS, if I can figure out how to write a mod, then I would have no doubt you could. Think of the mod as a find and replace type thing.. Find this piece of code and replace it with that. That is a simplistic way of putting it I know! If you are writing the code to start with then you have a good knowledge of coding and following mod creation code should not be too difficult.. Have you read up on it at all? Check out The Mod Manager Page on the TNG Wiki.

I would be happy to help, test and get your Mod sorted with you. Just ask.

 

Link to comment
Share on other sites

Thanks @RickM, I will take you up on it if there's sufficient interest. My proposal may not suit everyone... I have created an official Mod, but for this I would likely not use it and just update my code directly. It just feels like there's a lot of overhead (Mod packaging, Wiki, etc.) for smaller things, but I do see the value, so if I can partner with someone that's great. Thanks!

 

GOGGS

Link to comment
Share on other sites

On 4/17/2026 at 4:31 PM, Adri1 said:

Nice if it is possible to make a mod.

Send a feature request to Darrin. He may be able to add to a future release without a mod needed.

Link to comment
Share on other sites

On 4/18/2026 at 2:37 AM, Brett said:

Send a feature request to Darrin. He may be able to add to a future release without a mod needed.

Maybe both - feature request and mod for now? I will let @Adri1 and @RickM decide.

If the code below is inserted in the file globallib.php in the age function (function age($row)) right after the line: $age = $sign = $sign1 = $sign2 = '';  then 0 years will be replaced with month/months and day/days. For example (1 month) or (6 months 2 days). I did not do any language translation of month/months/day/days; this would require additions to the cust_text.php file(s) and the associated replacements in the code below.

	if(substr($datum_1_tr, 5, 2) != '00' && substr($datum_1_tr, 8, 2) != '00' && substr($datum_2_tr, 5, 2) != '00' && substr($datum_2_tr, 8, 2) != '00') {
		$diff = date_diff(date_create($datum_1_tr), date_create($datum_2_tr)); 
		$totdays = $diff -> format("%a"); $months = $diff -> format("%m"); $days = $diff -> format("%d");
		if((int)$totdays > 0 && (int)$totdays < 365) {
			if((int)$months == 1) $age  = " 1 month ";
			if((int)$months >  1) $age  = $months . " months ";
			if((int)$days   == 1) $age .= " 1 day ";
			if((int)$days   >  1) $age .= " " . $days . " days ";
			$age = trim($age);
			return $age;
		}
	}

Cheers

 

GOGGS

Link to comment
Share on other sites

Well, if this is all that is required to make the age less than one year appear, then indeed a simple feature request would be most worth while.. And given there is a Beta out for testing I will take it upon myself on behalf of @GOOGS and email Darrin directly..

It does seem like a lot of work to make a mod for such a simple change however if @Adri1 is not happy with making the coding change I am happy to create a mod, but not put it on the Wiki..

*****EDIT*****

Having tried the code and created one person with a DoB less than a year ago I DO NOT SEE ANY CHANGE in how the age is displayed. Still see (0 Years)..

@GOGGS There is code further along in this function that formats the age.. Might this have an impact on the display?? I have yet to email Darrin, and yes I will be pointing Darrin to this post and advising who provided the code.. <Smile>.

 

 

Link to comment
Share on other sites

@RickM I'm cool with whichever way this goes...

Regarding the code, I incorrectly assumed we were only talking about children that had already DIED at less than 1 year. If you move the code block I already sent AFTER the next if statement (below), it solves this problem... as long as the "living" checkbox has been marked. When a person is added with no death date, the field deathdatetr is still added to the database as "0000-00-00" regardless of living being checked or not. That next if statement uses today's date to calc age when living = 1 AND deathdate is blank AND burialdate is blank. We could change that too (I'm taking the living test out of my code)...

	if($row['living'] == "1" && !$datum_2 && !$datum_alt_2) {
		// Today
		$datum_2_tr = date ("Y-m-d", time() + ( 3600 * $time_offset ) );
	}

 

GOGGS

Link to comment
Share on other sites

Excellent @GOGGS,

I didn't even give those wee souls that had passed so early in life a thought.. Strange because I was thinking about it not so long ago for the current s/ware I am using! 

I will await a comment from @Adri1 and also see if Michel pops in before passing on to Darrin for his comment / hopeful inclusion! I'm guessing though, @Adri1 will want the Mod to make the change rather than he dealing direct with code..

I will slap something together and pop up here later!

****EDIT****
Slapped together Mod Zip
age_less_than_1_year.zip

 

Edited by RickM
Added Mod Zip file
Link to comment
Share on other sites

👍Thanks

Link to comment
Share on other sites

Many thanks for the replies and the efforts.

Of course it is not a crucial thing, but it would be nice if it is possible to show the correct age.

I have only a bit of knowledge of coding.

Is your mod now working and safe to use RickM?

Link to comment
Share on other sites

I installed the mod on my xampp version.

Result: it shows the correct age: months and days.

But, normally when you enter birthdate or deathdate as 1/2/2025 then it results in 01 feb 2025.

Now it stays as 1/2/2025.

So that is not correct.

I deleted the mod but then the input for dates stays as 1/2/2025.

How can I solve this.

Link to comment
Share on other sites

@Adri1

With the Mod installed on my Laragon Local Server, the date input seems to be correct.

Just checking you uninstalled and then deleted the Mod??

It may not matter, but what version TNG are you on?? Any other info might be helpful too!

@GOGGS might have an idea or two too! <smile>.

 

Link to comment
Share on other sites

The change I provided does not manipulate any of the dates; it just calculates from what is there. If there is no deathdate, it uses TNG's formula for today's date.

Maybe there is a "locale" issue? Dates are interpreted differently in EU vs. USA for example. I always enter 4 May 2025 instead of 4/5/2025 or 5/4/2025 to avoid this issue. TNG will try to interpret what is entered based on format and locale, but that could be confusing...

 

GOGGS

Link to comment
Share on other sites

My version is tng 15.0.3

We always enter dates like I mentioned: 1/2/2025 results in 01 feb 2025.

And that worked, but after installing your mod it did not work anymore.

Witch page(s) are involved?

Link to comment
Share on other sites

I didn't change how your dates work. Every page where a date is birth or death date is entered would be affected by entering in the format mm/dd/yyyy (which is how we do it in the USA, where in the EU (for example) they might use dd/mm/yyyy; that's why there's confusion. TNG will take your input of mm/dd/yyyy or dd/mm/yyyy and convert it to this: dd MON yyyy for display, and store in the "TR" fields (e.g. deathdatetr).

Using phpMyAdmin or by creating a TNG report, use this SQL to check your dates, datetr fields (e.g. YYYY-MM-DD, which is what my mod uses) and see how many people have negative or strange dates (I found a few of my own that were messed up): 

SELECT personID, birthdate, birthdatetr, deathdate, deathdatetr, datediff(deathdatetr, birthdatetr) AS days_old  FROM `tng_people` 
WHERE datediff(deathdatetr, birthdatetr) < 365 AND datediff(deathdatetr, birthdatetr) <> 0 
ORDER BY datediff(deathdatetr, birthdatetr);

Here's a few of mine:

Weird ages.png

 

GOGGS

Link to comment
Share on other sites

Also, here's where the preference is on entering the tricky date format:

Date config.png

 

GOGGS

Link to comment
Share on other sites

Indeed this could be a locale thing.. I wonder IF there might be someone from the EU or who might try the 'mod' to see what happens.. I'll ask an old friend @Rob Severijns if he might just check this PLEASE! <Smile>..

 

Link to comment
Share on other sites

Rob Severijns

Hi @RickM,

I'd be glad to help you out.

Will download and test it on TNG 15.0.5b1 and TNG 15.0.4

You will need to be patient though. Can't start testing any earlier then sunday afternoon.

Link to comment
Share on other sites

Rob Severijns

Took a quick look and the mod seems to be working just fine.

image.png

No conflicts found wtih Age at Event  & Age at Marriage mods.

Date settings:
image.png

Would like to see a , (comma) between months and days though or if you want to be more consistent with the Age at Marriage mod, use "and"

Tested on TNG 15.0.5b1 and TNG 15.0.4 with the standard Gregorian Calender

Hope this helps.
If you need any other testing just mention it and I will look at it on Sunday afternoon

Will send you a Dutch translation on Sunday

Link to comment
Share on other sites

@Rob Severijns,

Very much appreciate it Rob! I'm sure I can sort the comma out! <Smile> Did you see any issue with actual dates showing wrong??

Been having a little bit of a spin with getting translations to work! I know @GOGGS wasn't going there, however I figured one should at least give it a bash! 

Thank You!

 

Link to comment
Share on other sites

Michel KIRSCH

Rick and all,

I'll definitely follow Goggs' recommendations,

but only for my “Age at Marriage” and “Age at Event” mods.

As for TNG, I'll leave it to you to contact and deal with Darrin.... :-)

Michel

Goggs, thanks for the code...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...