- Impact
- 38
how can I generate a random timestamp (between now and a few seconds from now / before now) with PHP?
That is my PHP that does the update. The problem is I am doing this multiple times quickly and the same date/time is getting inserted for each banner (we are updating banners here) which as a result is causing trouble randomizing banners to display.
What I want to do:
Create a random time (in seconds) from now and a few seconds in the future. Just enough time so the banners don't get the same date_last_displayed value in each row.
I have searched everywhere for an easy way to do this and most don't explain how to randomize time without treating it as a string.
Any help is greatly appreciated.
PHP:
$this->db->Execute("UPDATE ".T_BANNERS." SET impressions=impressions+1, date_last_displayed=NOW() WHERE id=?",array($banner['id']));
That is my PHP that does the update. The problem is I am doing this multiple times quickly and the same date/time is getting inserted for each banner (we are updating banners here) which as a result is causing trouble randomizing banners to display.
What I want to do:
Create a random time (in seconds) from now and a few seconds in the future. Just enough time so the banners don't get the same date_last_displayed value in each row.
I have searched everywhere for an easy way to do this and most don't explain how to randomize time without treating it as a string.
Any help is greatly appreciated.






