[Gambas-user] Random date question

Gianluigi bagonergi at gmail.com
Fri Sep 27 17:05:28 CEST 2019


I'm looking for a method to randomly get the *only* date to populate a test
database.
I want to get a precise range i.e. from 2010-01-01 00:00:00 to 2019-12-31
00:00:00, passing all dates with time 00:00:00.
Rand with the integer part of the date seems to work well.
If I use Date.FromUTC in my time zone (-7200) does it work, would it still
work with all the other time zones?

I have attached the test:

'-----------------------------------------
Public Sub Main()

  DateRange(Date(2010, 1, 1, 0, 0, 0, 0), Date(2019, 12, 31, 0, 0, 0, 0),
65000)

End

Private Sub DateRange(date1 As Date, date2 As Date, number As Integer)

  ' Print System.TimeZone
  date1 = Date.FromUTC(date1)
  date2 = Date.FromUTC(date2)
  Randomize 3
  For i As Integer = 1 To number
    Print Date(Rand(Int(CFloat(date1)), Int(CFloat(date2))))
  Next

End
'-------------------------------------------

There would also be this variation:

'-------------------------------------------
  ...
  date2 = Date.FromUTC(date2 + 1)
  Randomize 3
  For i As Integer = 1 To number
    Print Date(Int(Rnd(date1, date2)))
  Next

End
'-------------------------------------------

Regards
Gianluigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190927/e4d53912/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RandomDateTest-0.0.1.tar.gz
Type: application/gzip
Size: 11472 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190927/e4d53912/attachment.gz>


More information about the User mailing list