There is a task: to limit the storage time, the restriction is chosen by the user.

Nr: 2 inputa, in one we write a number, and in another we select the type of storage from the dropdown list

2 | hours (minutes, days, week)

Task with storage for several days and weeks did.

but how to do 1 and 2? How to make storage for several hours / minutes?

Here is how I did the storage days

Where

$row_c['load_date'] - время загрузки файла. $current_d - нынешнее время. $row_c['time_save'] - время хранения выбранное пользователем. 

>

 $count_date = $row_c['load_date'] - $current_d; $difference = intval(abs(strtotime($row_c['load_date']) - strtotime($current_d))); // Количество дней $finish_c_d = (int)$int_count_date = $difference / (3600 * 24); // Проверка и удаление // Проверка дней if ($finish_c_d > $row_c['time_save']) { echo "время истекло, данные удалились! id= ".$row_c['id']; }else{echo "Рано удалять! id= ".$row_c['id'];} } 
  • when you create a record, write the date, when you need to delete it (i.e., calculate it immediately), then when you access the record, check whether it is available or not. And periodically run cron to remove old data. On mysql it would be like this: select * from table_name where time_delete > now() to get available, select * from table_name where time_delete <= now() to get obsolete. Because Since we no longer work with hours / minutes, etc., but we work with one time, we can add any interval of any kind (at least 55 seconds, at least two years and 10 days). Something like this. - BOPOH
  • Yes, if you specify the exact time and date, it turns out, it's just a little inconvenient for users to choose a date, so I had to do this: 1 input in which a number from 1 to 24 is entered and 1 select from which they select the storage type (minutes, hour, day ) and after that the data is saved, as a result, the base looks like this: date_load | time_load | time_save | type_save 11/26/2015 | 11.00.02 | 2 | hours date_load and time_load are automatically recorded after the data is loaded. something needs to be done with time _load, time_save, type_save - Ismar
  • you need to do something so that it looks at how many hours ago the file was loaded, then see how many hours to store it, if time_load> time_save, then delete it. It is necessary to turn time_save into hours or something 0_o because time_load in this format is 11:00:12 and time_save in this 2 hours - Ismar
  • and how to add 11 hours to this time at 11:00:12? and also add 11 minutes to 11:00:12? - Ismar
  • Thank you very much, I did everything - Ismar

1 answer 1

 $time = date($load_time); $time2=$row_c['time_save']." hours"; $vychislenie_save_time = date('H:i:s', strtotime($time2, strtotime($time))); $current_now_t = date('H:i:s', time()); echo $vychislenie_save_time."--------".$row_c['id']." <br>"; echo $current_now_t."current time -------<br>"; if ($current_now_t > $vychislenie_save_time) { echo "время истекло, данные удалились! id= ".$row_c['id']; }else{echo "Рано удалять! id= ".$row_c['id'];}