Filling gaps in dates


Posted on 16th Feb 2014 07:03 pm by admin

So i'm doing a query for sales data and my return array looks like this

('date' => '2008-11-01 00:00:00', 'total' => 1),
('date' => '2008-11-03 00:00:00', 'total' => 3),
('date' => '2008-11-04 00:00:00', 'total' => 3),
('date' => '2008-11-07 00:00:00', 'total' => 5),
('date' => '2008-11-12 00:00:00', 'total' => 1)

There are obviously gaps in my dates. What i'm trying to figure out is the best approach to filling those empty dates with a total of 0 so my graphs don't look all jacked up because i'm not providing all the data. Does anyone have an idea how to approach this problem to fill in the missing dates? I'd like the array to look like the following:


('date' => '2008-11-01 00:00:00', 'total' => 1),
('date' => '2008-11-02 00:00:00', 'total' => 0),
('date' => '2008-11-03 00:00:00', 'total' => 3),
('date' => '2008-11-04 00:00:00', 'total' => 3),
('date' => '2008-11-05 00:00:00', 'total' => 0),
('date' => '2008-11-06 00:00:00', 'total' => 0),
('date' => '2008-11-07 00:00:00', 'total' => 5),
('date' => '2008-11-08 00:00:00', 'total' => 0),
('date' => '2008-11-09 00:00:00', 'total' => 0),
('date' => '2008-11-10 00:00:00', 'total' => 0),
('date' => '2008-11-11 00:00:00', 'total' => 0),
('date' => '2008-11-12 00:00:00', 'total' => 1)

No comments posted yet

Your Answer:

Login to answer
234 Like 46 Dislike
Previous forums Next forums
Other forums

SQL Query/echo not working
Hey all,

I'm trying to run (what I thought) was a simple operation and it isn't working. I h

printing links
Hi every1

i am connecting to a table in sql and the looping through with a while ($ var = my

How to assign JS screen.width to ASP.Net variable
I've got this ASP.net routine that gets the cookie value of the screen width, but now I need to chan

Storing the referrer in session... problems with tabs
Hello All

I am currently working on an ERP project based on the MVC methodology, when a user

Need help with an email blocker for a guessbook
I am new with php and here is a simple guessbook page but I am being hit with spam from a group of t

Connection Timeout
I'm using xmii 12.0

I'm calling a transaction as a web service from a windows application

mod_rewrite.c on windows ??
why it's not working on windows while it's working on other hosts???

this is the code i got

Logic question
im wondering what's the best method to do the above list:

it is for alliance @ MMORPG game

Just cannot get 'area' to submit to db using same php code as already used
Basically all i have done is just modified some code and added an area section.
The form is allre

PHP Blog help
Need help with posting comments in a word press blog? I have a comments page where the comments are

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash