Skip to content

Instantly share code, notes, and snippets.

@samcrosoft
Created September 13, 2013 13:09
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samcrosoft/6550473 to your computer and use it in GitHub Desktop.
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
<?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);
}
@Zarky2k2
Copy link

thanks <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment