<--- --------------------------------------------------------------------------------------- ---- Blog Entry: Creating Random Dates in ColdFusion: RandDateRange( dtFrom, dtTo ) Author: Ben Nadel / Kinky Solutions Link: http://www.bennadel.com/index.cfm?dax=blog:121.view Date Posted: Jul 7, 2006 at 3:08 PM ---- --------------------------------------------------------------------------------------- ---> // 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 );