Yesterday I asked another question to calculate time.
Now I realized, that it makes no sense to use a second table for my project because everything that is necessary is already given in my first table. So, for the moment I use two tables where I insert two timestamps:
$time = "INSERT INTO table2 ( a, b, c) VALUES (NOW(),NOW() + INTERVAL 14 DAY,(unix_timestamp(NOW()+ INTERVAL 14 DAY)) - unix_timestamp(NOW()))";
Like I already said, it could be much easier and the same result will be reached without a second table. Now my problem is, this is the first time I have worked with timefunctions in php. There are a lot of different functions that I do not really understand.
I think to solve my problem I can use something like:
$row = fetch_assoc()
$old_timestamp = $row->b;
$actual_time = mktime(); //which makes an actual timestamp
$seconds = '1209600'; //which is exactly the timeperiod of 14 days
$added = $old_timestamp + $seconds; //which adds the seconds to the old timestamp and should be the same as NOW() + INTERVAL 14 DAY from the VALUE of the query
$date_to_check = $added - $actual_time;
if $date_to_check <= 0 {
do something }
Is this possible? I would really appreciate if there is someone who can help. thanks a lot.
UPDATE
For everyone who likes to know what i have in mind. Here is the code for the actual way:
$time_check = $db->query("SELECT (B <= NOW()) AS var FROM table2 WHERE x='$x'");
while ($row = $time_check->fetch_object()){
if (($row->var != 0) && ($var1 === '0')){
$update_status = $db->query("UPDATE table1 SET var1='1' WHERE x='$x'");{
$delete_timecount = $db->query("DELETE FROM table2 WHERE x='$x'");
}
}
}
I would like to accomplish the same result without a second table.
I can't really understand what you are trying to do. It appears that you are trying to recognize when 14 days have elapsed after someone's registration in order to do something.
if (time() > $old_timestamp + 1209600) {
// It's been 14 days
// Do something
}
I used time
, which simply returns the current time. Do you understand what a timestamp is?