Reputation: 1699
I am using jQuery date picker in my codeigniter project
I use it like this in my view
<script>
$(function() {
$( "#from-datepicker" ).datepicker();
});
</script>
<script>
$(function() {
$( "#to-datepicker" ).datepicker();
});
</script>
<div style="float:left; width:330px">
<input name="from-date" type="text" id="from-datepicker" />
</div>
<div style="float:left; width:330px">
<input name="to-date" type="text" id="to-datepicker" />
</div>
In my controller I have
public function titlesDownloads(){
if($_POST){
$form = $this->input->post();
$boxes = $form['boxes'];
$titles = $form['titles'];
$from_date = date('Y-m-d',strtotime($form['from-date']));
$to_date = date('Y-m-d',strtotime($form['to-date']));
$data['titles_downloads'] = $this->Statistic_model->getTitlesDownloads($boxes, $titles, $ipsegments, $from_date, $to_date);
$data['from_date'] = $from_date;
$data['to_date'] = $to_date;
$this->load->view('statistic/titles-downloads', $data);
}
}
In my model I have the function to get the count of downloads as
public function getTitlesDownloads($boxes, $titles, $from_date, $to_date){
$query = $this->db->select('mc_boxes_idmc_boxes, mc_boxes.location, idtitle_history, titles.title, COUNT(mc_boxes_has_downloads.idtitle_history) AS Titles_Downloads ')
->from('mc_boxes_has_downloads')
->join('mc_boxes', 'mc_boxes_has_downloads.mc_boxes_idmc_boxes = mc_boxes.idmc_boxes', 'left')
->join('titles', 'mc_boxes_has_downloads.idtitle_history = titles.idtitles', 'left')
->where_in('mc_boxes_idmc_boxes', $boxes)
->where_in('idtitle_history', $titles)
->where('actiontime >=', $from_date)
->where('actiontime <=', $to_date)
->group_by('mc_boxes_idmc_boxes')
->group_by('idtitle_history')
->get();
$data = $query->result_array();
return $data;
}
Now, for a specific title id=7 there are 4 downloads in month of june. but when I run the query it returns me three. The last download which was on june 30 is skipped.
I think the date picker is skipping the upper and lower bound of the selected dates. Though in my query I wrote >= startdate and >=enddate.
Why it is skipping the lastdate ?
Any idea?
Thanks
Upvotes: 1
Views: 7685
Reputation: 38087
Since you are only passing a date and no time, it is probably assuming the time is Midnight. So less than Midnight on Jun-30 precludes anything from Jun-30 from being displayed.
Your best bet might be to just add a day and use less than to find anything that occurred the day before.
Upvotes: 1