Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I wish to return the difference between
start_date
and
account_add_date


For Example:
The user added an account on 1st December 2015 and started the account on 1st March 2016 so the difference is 3 months.

My query is returning nothing, what is the problem ?

What I have tried:

function get_age() {
$mem_id = $this->session->userdata('id');
$query = $this->db
->select("12*(YEAR('account_add_date') - YEAR('start_date')) + (MONTH('account_add_date') - MONTH('start_date')) AS differenceInMonth")
->where('mem_id', $mem_id)
->get('bank');

return $query;
}
Posted
Comments
Mohibur Rashid 2-Mar-16 18:58pm    
try this mysql link
Ben Oats 2-Mar-16 19:08pm    
Thank you, Ill give it a go
ZurdoDev 3-Mar-16 7:38am    
Please post as solution.
Sinisa Hajnal 3-Mar-16 6:52am    
Most (All?) databases have datediff or equivalent function. Read the docs (help).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900