INSERT for date range


Posted on 16th Feb 2014 07:03 pm 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

No comments posted yet

Your Answer:

Login to answer
256 Like 53 Dislike
Previous forums Next forums
Other forums

SHOW TABLES Help
Hi all

I have the following

Code: [Select]<?php
$sql = "SHOW TABLES&quo

PHP Cannot redeclare class
I have 6 files, and two of them do not seem to want to play well. I keep getting a "Cannot rede

Need PHP help... have all the elements... just need help putting them together :
Hey Guys,

I was wondering if someone could help me. I am doing a website for a client which

IF Statement & Two Tables With Different Echoes
I'm retrieving two tables in a single query using UNION ALL, like so:

Code: $query = "SE

natcasesort works on one server but not on another
Hi

I have a problem that I was hoping that someone can help me with.

I'm trying to use

Apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?

need help in update query
i create a form for update. there are 8 columns in my mysql table. on my main page all the data is r

UDS 4.0 Datatype issue
UDS 4.0.322 -- connecting to NI Labview 9.0

When using connection method: Cache with live

Working with Dates, help.
Sooo to make a long story short, here's what im trying to accomplish.

I need to create a drop

Recording popularity by day, week.. all time?
Hey everyone, I'm creating a site designed around users uploading music. How can I implement a syste

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