Created
September 13, 2013 13:09
-
-
Save samcrosoft/6550473 to your computer and use it in GitHub Desktop.
A PHP Method to generate random dates
between two dates specificed with a format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Method to generate random date between two dates | |
* @param $sStartDate | |
* @param $sEndDate | |
* @param string $sFormat | |
* @return bool|string | |
*/ | |
function randomDate($sStartDate, $sEndDate, $sFormat = 'Y-m-d H:i:s') | |
{ | |
// Convert the supplied date to timestamp | |
$fMin = strtotime($sStartDate); | |
$fMax = strtotime($sEndDate); | |
// Generate a random number from the start and end dates | |
$fVal = mt_rand($fMin, $fMax); | |
// Convert back to the specified date format | |
return date($sFormat, $fVal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks <3