INSERT for date range

Posted on 16th Feb 2014 by admin

Hi all

I have the following table

Code: [Select] `date` date
`day` int(2)
`month` int(2)
`year` int(4)
If I pass a date range in PHP, such as

Code: [Select]$datefrom = '2009-02-20';

$dateto = '2009-02-25';
How can I get it to INSERT a record for every date between that date range?

So with that example date range, it would do

Code: [Select]INSERT INTO `dates` (`date`, `day`, `month`, `year`) VALUES
('2009-02-20', '20', '02', '2009'),
('2009-02-21', '21', '02', '2009'),
('2009-02-22', '22', '02', '2009'),
('2009-02-23', '23', '02', '2009'),
('2009-02-24', '24', '02', '2009'),
('2009-02-25', '25', '02', '2009')
but not do an INSERT if any of those dates already exists in the database.

Any help would be great

Thanks

Other forums