Reputation: 137
in employees timeentry system each employee will enter the no of hours worked on a daily basis.To reduce the work i want to copy the last week time entries ie (from Mon - Fri) to the present week ie(mon-friday) I am able to fetch the last week data from my table as mentioned below
$query = "select * from table_name where (date(start_time) >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY AND date(start_time) < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY)";
Now i want to insert the data fetched from last week to be in the present week lets for in this ie from(1july to 5july) i am using php and mysql
plz suggest how do i insert for the present week
Upvotes: 0
Views: 107
Reputation: 9933
Simply add seven days to the dates in your SELECT
query and INSERT
them
Something like
INSERT INTO timeentry
SELECT employeeId, DATE_ADD(date(start_time), INTERVAL 7 DAY), --...
FROM timeentry
WHERE (date(start_time) >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND date(start_time) < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY)
Upvotes: 0
Reputation:
if you want a simple insert of new rows with same values.
do this, create the select query, and create an insert query above it that will simply insert new rows and will add 7 days to the time reported.
something like this:
insert into `theTable`
select DATE_ADD(theHour, INTERVAL 7 DAYS)
from `theTable`
syntax may be wrong but this is the idea.
Upvotes: 1