[AccessD] Create a random date/time
Jim Lawrence
accessd at shaw.ca
Fri Aug 28 11:42:56 CDT 2015
Hi Gustav:
That definitely could be useful for some many types of problems.
Jim
----- Original Message -----
From: "Gustav Brock" <gustav at cactus.dk>
To: "Access Developers discussion and problem solving" <accessd at databaseadvisors.com>
Sent: Friday, August 28, 2015 8:29:44 AM
Subject: [AccessD] Create a random date/time
Hi all
Have you ever wondered how to create a random date/time?
Well I hadn't, but it is not that difficult. The trick is using Rnd twice:
RandomDate = CDate((CLng(#12/31/9999#) - CLng(#1/1/100#)) * Rnd * Rnd + CLng(#1/1/100#))
The full story is here:
http://stackoverflow.com/a/32265346/3527297
If you want a value within a given range, you can use this simple function:
<code>
Public Function DateRandom( _
Optional ByVal UpperDate As Date = #12/31/9999#, _
Optional ByVal LowerDate As Date = #1/1/100#) _
As Date
' Generates a random date/time - optionally within the range of LowerDate and/or UpperDate.
'
' 2015-08-28. Gustav Brock, Cactus Data ApS, CPH.
Dim RandomDate As Date
RandomDate = CDate((CLng(UpperDate) - CLng(LowerDate)) * Rnd * Rnd + CLng(LowerDate))
DateRandom = RandomDate
End Function
</code>
/gustav
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
More information about the AccessD
mailing list