I am using strtotime function to create a list to retrieve items that were sold in a specific time

Viewed 23

I am trying to make a POS system. My goal is to be able to create lists of items sold according to time criteria.

I have used strtotime function successfully for items sold in last month:

$start_date = date("Y-m-d",strtotime('-31 days'));
$end_date = date("Y-m-d 23:59:59");

and last week, yesterday..

But I would like to be able to retrieve items sold today

$start_date = date("Y-m-d",strtotime('-0 days'));
                $end_date = date("Y-m-d  23:59:59");

Here is what I am working with so far

            case 'sales_today': 
            case 'sales_past_day': 
            case 'sales_past_week': 
            case 'sales_past_month':
            
            $start_date = false;
            $end_date = false;
            
            
            if ($criteria == 'sales_today')
            {
                $start_date = date("Y-m-d",strtotime('+0 days'));
                $end_date = date("Y-m-d  23:59:59");
                
            }
                elseif ($criteria == 'sales_past_day')
            {
                $start_date = date("Y-m-d",strtotime('-1 days'));
                $end_date = date("Y-m-d  23:59:59");
                
            }
            
            elseif ($criteria == 'sales_past_week')
            {
                $start_date = date("Y-m-d",strtotime('-7 days'));
                $end_date = date("Y-m-d  23:59:59");
                
            }
            elseif('sales_past_month')
            {
                $start_date = date("Y-m-d",strtotime('-31 days'));
                $end_date = date("Y-m-d 23:59:59");
            }
            $this->load->model('Sale');
            $item_ids = $this->Sale->get_item_ids_sold_for_date_range($start_date, $end_date, $supplier_id);

this is working good so far , would like to know if +0 or -0 days is the correct way for getting all the items sold from 23:59:59 to the current time? Thanks!

1 Answers
Related