Jump to content

Archived

This topic is now archived and is closed to further replies.

eranwein

random date

Recommended Posts

work out a random date between start of year and today

[code]

function getrandomdate($date1, $date2, $format = "Y-m-d")
{
   $randomdate = rand(strtotime($date1), strtotime($date2));
   return date($format, $randomdate);
}

// mysql date format, although strtotime works on many date formats.
$firstdate = "2006-01-01";
$lastdate = "2006-03-14";


echo "random date is ".getrandomdate($firstdate, $lastdate);
[/code]

give that a go. to get the date back in a different format, just add a third parameter to the call to 'getrandomdate' function, else it'll come back in mysql format.

Cheers
Mark

Share this post


Link to post
Share on other sites
thanks. works great.

to all the others who reads it, notice that there is a missing $ on date2.

thanks again, eran

Share this post


Link to post
Share on other sites
[!--quoteo(post=354844:date=Mar 14 2006, 11:49 AM:name=eranwein)--][div class=\'quotetop\']QUOTE(eranwein @ Mar 14 2006, 11:49 AM) [snapback]354844[/snapback][/div][div class=\'quotemain\'][!--quotec--]
thanks. works great.

to all the others who reads it, notice that there is a missing $ on date2.

thanks again, eran
[/quote]

oops, my bad. i changed it now

Cheers
Mark

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.