Answer the question
In order to leave comments, you need to log in
Counting the day using time()?
Hello everyone, I'm puzzled on how to implement the countdown of the day when using the time() function
Example:
The user can only perform one action per day, BUT the implementation should be as follows. A day is not counted as an addition to time() + 86400 seconds, but a calculation up to 00.00. Those. at 00.01 are already considered a new day as it should be. And the user can perform the action again!
Answer the question
In order to leave comments, you need to log in
Em. Why do you need time here?
A person performed an action - they wrote down one. At the onset of 00:00:00, all units were reset to zero and you can perform the action again, no?
Advice is a reminder. Do not forget to take into account the time zones of users in your scripts, otherwise it will turn out that for one day it starts and ends at 0:00 and for another 3:00
And one more reminder tip. If you use mathematics with seconds, do not forget that in a year there is a day of 23 hours and a day of 25 hours. On the days of the clock change.
$last_action_time = '2010-12-07 26:35:21'; // здесь должно быть сохраненное из базы
if(strtotime($last_action_time) < strtotime('today')) {
// allow
} else {
// disallow
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question