N
N
NiGP2010-12-07 07:21:01
PHP
NiGP, 2010-12-07 07:21:01

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

5 answer(s)
I
IDDQD, 2010-12-07
@NiGP

the simplest option is date('Ymd', time())

A
Alexey Ashurok, 2010-12-07
@AotD

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?

N
niko83, 2010-12-07
@niko83

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

S
Shedar, 2010-12-07
@Shedar

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.

S
Stalker_RED, 2010-12-08
@Stalker_RED

$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 question

Ask a Question

731 491 924 answers to any question