<cffunction name="RandDateRange" access="public" returntype="date" output="false" hint="This returns a random date between the two given dates (inclusive)."> <!--- Define arguments. ---> <cfargument name="FromDate" type="date" required="true" /> <cfargument name="ToDate" type="date" required="true" /> <cfscript> // Define the local scope. var LOCAL = StructNew(); // Get the difference in seconds between the two dates. LOCAL.TimeDifference = DateDiff( "s", ARGUMENTS.FromDate, ARGUMENTS.ToDate ); // Create a random time increment based on the second difference. // The time span object is a representation of time-length in // terms of a single floating-point number. LOCAL.TimeIncrement = CreateTimeSpan( 0, // Days 0, // Hours 0, // Minutes RandRange( // Seconds // Our smallest possible time increment. 0, // Our largest possible time increment that will not // put us past the ToDate. LOCAL.TimeDifference ) ); // Get a new random date based on the FromDate and the random // time span. LOCAL.RandomDate = (ARGUMENTS.FromDate + LOCAL.TimeIncrement); // This random date now is formatted like a TimeSpan object, // meaning that it is in the form of one floating point number. return( LOCAL.RandomDate ); </cfscript> </cffunction>