Age from DOB

Javascript coding ..

Moderators: gesf, Michalio

Post Reply
Dharmeshdhabu
php-forum Active User
php-forum Active User
Posts: 32
Joined: Sat Jul 23, 2022 6:45 pm

I have php programme for hospital managment. I calculate age from DOB. I wants to add "Yr" after age calculation. Please guide me how to add "Yr" after calculation. Below is my code.

Code: Select all

var dob11 = new Date(document.getElementById('Age1').value); 
                                                
												
													
User avatar
Michalio
Moderator
Moderator
Posts: 317
Joined: Sun Jul 18, 2021 1:33 pm
Location: Poland

what the document.getElementById('Age1').value contains? is a age like "30"?
you can do this:

Code: Select all

var age = document.getElementById('Age1').value;
const ageString = age + 'Yr';
or

Code: Select all

var age = document.getElementById('Age1').value;
const ageString = `${age}Yr`;
Free coding lessons: https://php-forum.com/phpforum/viewtopic.php?t=29852
Dharmeshdhabu
php-forum Active User
php-forum Active User
Posts: 32
Joined: Sat Jul 23, 2022 6:45 pm

Thakns for your reply. Really it is simple. I just added yr as " $age+"Yr" and it worked. Thakns
Post Reply