Calculate PATIENTS age based on two dates stored in TABLE using Codeigniter - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Calculate PATIENTS age based on two dates stored in TABLE using Codeigniter (/showthread.php?tid=83046) |
Calculate PATIENTS age based on two dates stored in TABLE using Codeigniter - optic4predator1 - 09-15-2022 I'm working on a college project using Codeigniter and I want to display the following data by showing the number of data in real time. so i would like to calculate the age of patients based on two dates, birthdate date and registration date, I would like to know the age of the patient at the time of treatment so for this i have a TABLE named THE_PATIENT which contains id, patient_name, date_of_birth, abou_patient, created_at and a TABLE named MEDICAL_INTERVENTION which contains id, patient_id, disease_type_id , created_at. So i would like to display the total of MEDICAL_INTERVENTIONS recorded and JOIN the THE_PATIENT Table, calculate age of patients from date_of_birth to created_at, and add cases if age between 1y to 15y range = kid , else if age between 16y to 70y range = adult , else if age over 70 range = old_adult , after geting data i want to group_by age range and display it in my view. Any help will be appreciated Thank you for your assistance, my respects. Code: class My_model extends CI_Model { RE: Calculate PATIENTS age based on two dates stored in TABLE using Codeigniter - optic4predator1 - 09-15-2022 (09-15-2022, 02:23 AM)optic4predator1 Wrote: I'm working on a college project using Codeigniter and I want to display the following data by showing the number of data in real time. so i would like to calculate the age of patients based on two dates, birthdate date and registration date, I would like to know the age of the patient at the time of treatment so for this i have a TABLE named THE_PATIENT which contains id, patient_name, date_of_birth, abou_patient, created_at and a TABLE named MEDICAL_INTERVENTION which contains id, patient_id, disease_type_id , created_at. So i would like to display the total of MEDICAL_INTERVENTIONS recorded and JOIN the THE_PATIENT Table, calculate age of patients from date_of_birth to created_at, and add cases if age between 1y to 15y range = kid , else if age between 16y to 70y range = adult , else if age over 70 range = old_adult , after geting data i want to group_by age range and display it in my view. Any help will be appreciated Thank you for your assistance, my respects. RE: Calculate PATIENTS age based on two dates stored in TABLE using Codeigniter - InsiteFX - 09-16-2022 Code: SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(now(),'yourDateofbirth')), '%Y')+0 AS dateBorn; RE: Calculate PATIENTS age based on two dates stored in TABLE using Codeigniter - optic4predator1 - 10-03-2022 Thank you @InsiteFX for your support |