eranwein Posted March 14, 2006 Share Posted March 14, 2006 is there any function that returns a random date between two givven dates? Quote Link to comment https://forums.phpfreaks.com/topic/4911-random-date/ Share on other sites More sharing options...
redbullmarky Posted March 14, 2006 Share Posted March 14, 2006 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.CheersMark Quote Link to comment https://forums.phpfreaks.com/topic/4911-random-date/#findComment-17316 Share on other sites More sharing options...
eranwein Posted March 14, 2006 Author Share Posted March 14, 2006 thanks. works great. to all the others who reads it, notice that there is a missing $ on date2.thanks again, eran Quote Link to comment https://forums.phpfreaks.com/topic/4911-random-date/#findComment-17319 Share on other sites More sharing options...
redbullmarky Posted March 14, 2006 Share Posted March 14, 2006 [!--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 nowCheersMark Quote Link to comment https://forums.phpfreaks.com/topic/4911-random-date/#findComment-17320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.