0

I have a table structure something like :

id | name | start_time | duration 
1    xyz      05:00 PM     4

Code

$from_time=9:30 AM;
 $sessionData=$this->db->where('start_time>=',$from_time)->get('user_session')->result();

In the above code i want end time calculated but i want endtime calculated from duration such as in my case for 5:00 pm endtime should be 9:00 pm. I want to select those rows only.

user3653474
  • 3,393
  • 6
  • 49
  • 135

1 Answers1

0

You can do that by using Mysql function Date_add. It would look like so:

SELECT * from `Hours` where DATE_ADD(start_time, INTERVAL duration HOUR) >= '07:00'

I have made a table that looks like: id name start_time duration

1   test    05:00:00    6
2   early test  05:00:00    1
3   late test   05:00:00    11

When I execute the query I do get the following results:

id  name    start_time  duration
1   test    05:00:00    6
3   late test   05:00:00    11

I don't think however you would be able to use the codeigniter query builder for this one. I would suggest querying directly the database by $result = $this->db->query($your_query);

You would however need to escape your data if there is user input in this one.

Mitko Delibaltov
  • 486
  • 1
  • 6
  • 16