Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Generate random timestamp?

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch
Impact
38
how can I generate a random timestamp (between now and a few seconds from now / before now) with PHP?

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.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
hi,

instead of "randomizing" your timestamp as you put it, you could order your data by the timestamp and id

Order by timestamp, id....

that way you will get the banners sorted in the correct order
 
0
Close
You can convert your timestamp to an integer, and create a random number & add it on to the time. No need to work with strings. Look at the time() function
 
0
Close
geronimo said:
hi,

instead of "randomizing" your timestamp as you put it, you could order your data by the timestamp and id

Order by timestamp, id....

that way you will get the banners sorted in the correct order

Yes thats exactly what I did to fix this, order by date_last_modified, rand()

and that seems to work. I just wanted to see how this would be done like the last poster said, by adding an integer.
 
0
Close
fair enough, glad you fixed it.
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back