how to populate a table with dates

I would like a select statement that creates all the dates & times (down to the minute level) between two different dates.  All dates and times would be in the following format:

'2007-08-01 12:25'

So if the start time was '2007-08-01 11:58' and the end time was '2007-08-02 00:02' then the statement should return the following:

2007-08-01 11:58
2007-08-01 11:59
2007-08-02 00:00
2007-08-02 00:01
2007-08-02 00:02


Server info:
MySQL 5.0.45-community-nt via TCP/IP
MySQL Client Version 5.1.11
InnoDB tables
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AFAIk not possible as there is no pseudo table where you could select from which would generate dummy records. You might write a stored procedure that creates the records or use a scripting language (like php) to do this.
Actually there is a way to do this and you'll be pleased to know it can be done w/o relying a massive set of data in some temporary table to do it.  You will need to use a table but it can be quite small.

For the sake of simplicity I'm going to assume you're solution is only looking to list the minutes within a 24 hour period.  Although this solution can be expanded to provide a list of minutes accross many days, such a solution would require a little more explanation (abliet not too terribly much) but I presume you're lists aren't going to be that long.  If they are just let me know and I can assist you through the additoinal changes required.

Now for the solution

Step 1:  Create a table name tblX10 with One field and name it X10.  Make the data type Byte.  Set the data validation rule to be as follows...

Between 0 And 9

Step 2: Add 10 records (values) to the tblX10.  Create 10 records with values 0 - 9.   (0, 1, 2, 3, 4, 5, 6, 7, 8 and 9)

Step 3: Create a query using the SQL code below and name it qryMin.

SELECT CDate(CDbl(tblX1000.X10 & tblX100.X10 & [tblX10].[X10] & tblX1.X10)/1440) AS T
FROM tblX10 AS tblX1, tblX10, tblX10 AS tblX100, tblX10 AS tblX1000
WHERE ((([tblX1000].[X10] & [tblX100].[X10] & [tblX10].[X10] & [tblX1].[X10])<=1440));

Step 4: Without knowing the table structure for your particular situation I'll take the liberty of assigning names to the table and it's fields.  Let's give your table the name of "tblLog" and give it 2 date fields named [Start] and [End] respectively.  Of course the actual names should not include the brakets or quotes.  

Step 5: The query below will avail the list you desire.  Although you may have to update the name "tblLog" to match that of you're actual table and/or update the date field names [Start] and [End] according to the name you're actually using everything else about the query should work as is.

SELECT Format([tblLog].[Start]+[qryMin].T,"dd/mm/yyyy hh:nn AM/PM") AS Minutes
FROM tblLog, qryMin
WHERE (((qryMin.T)<=CDate([tblLog].[End]-[tblLog].[Start])))
ORDER BY qryMin.T;


Believe it or not that's all there is to it.  The result will be a table of minutes that start and end between the Dates/Times provided in your table [Start] and [End] respecively.  

Note: The above solution presumes you will not need to list more than 24 hours worth of minutes and that the Start Date preceeds the End Date.  Other than that it'll work as is.

Well there you go, just let me know if you have any questions.

One correction to my last post.  The final query needs one little tweek if you want it to display the last minute.  Below is the updated version of this query in Step 5 above....

SELECT Format([tblLog].[Start]+[qryMin].T,"dd/mm/yyyy hh:nn AM/PM") AS Minutes
FROM tblLog, qryMin
WHERE (((qryMin.T)<=CDate([tblLog].[End]-[tblLog].[Start])+CDate(CBool([tblLog].[End]-[tblLog].[Start])/-1440)))
ORDER BY qryMin.T;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.