display every date in a date range (1 Viewer)

kobiashi

Registered User.
Local time
Today, 16:51
Joined
May 11, 2018
Messages
258
hi all


im trying to display all days in a range, i have a chart that shows a running 30 day window, what i want to do is show all days, in that 30 day window, whether an event occurs on a day or not, i have read that the only way to do this is have a table with all dates in the table, is there another way to do this?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:51
Joined
Aug 30, 2003
Messages
36,125
Not that I know of. I append the required dates into a table used for that purpose before proceeding.
 

June7

AWF VIP
Local time
Today, 07:51
Joined
Mar 9, 2014
Messages
5,470
Consider following found code, no guarantee can make practical use of:

PARAMETERS [StartDate] DateTime, [EndDate] DateTime;
SELECT DISTINCT Format([StartDate]-1+100*Abs([Hundreds].[id] Mod 10)+10*Abs([Tens].[id] Mod 10)+Abs([Ones].[id] Mod 10)+1,"mm/dd/yyyy") AS Dt, 1 AS Data
FROM MSysObjects AS Ones, MSysObjects AS Tens, MSysObjects AS Hundreds
WHERE ((([StartDate]-1+100*Abs([Hundreds].[id] Mod 10)+10*Abs([Tens].[id] Mod 10)+Abs([Ones].[id] Mod 10)+1) Between [StartDate]-1 And [EndDate]));
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:51
Joined
Feb 19, 2013
Messages
16,607
@June - that's neat, new one for me - by the looks of it, the limit is 999 days which should enough for most people, or just add a 'thousands' table to take it up to 9999. Risk is that one of the numbers is missing, but unlikely.

Subject to that risk you can make it faster by only including ID's<0
 

kobiashi

Registered User.
Local time
Today, 16:51
Joined
May 11, 2018
Messages
258
hey all thanks for the help, i decided to use a table in the end, as there was only a few thousand entries for 15 years.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:51
Joined
May 21, 2018
Messages
8,527
In your case you could make a table with just 30 entries. When the user selects the start date before opening the chart, just run a loop updating the table with the needed 30 days. Since you are just updating and not continuously adding/deleting it should not bloat. If it is always the next 30 days out then you can update it on start up.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:51
Joined
Oct 29, 2018
Messages
21,467
Hi,


If I may offer another potential approach using a Cartesian query. I have an example of this on my blog site, which basically takes a tally table that MajP mentioned above and then produce every dates within a date range using a cartesian query.



Just my 2 cents...
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 08:51
Joined
Oct 29, 2018
Messages
21,467
similar to post #3?

Similar but simpler and easier to understand. However, it requires a tally table. Having a tally table will also make the approach highly extensible.

Just my 2 cents...
 

Users who are viewing this thread

Top Bottom