Data Generator: How to generate random dates between min and max?

ifernan

Member²
Hi.

I have been reading User's Guide and I have discover this for Random function of Data Generator:

"Random([Min], Max) Returns random numbers between Min and Max. If only Max is specified, Min is set to 0. For date fields you can enter dates for Min and Max."

But I am missing something because I have tried several ways for setting min and max value of the date and nothing works for me.

I have tried:
- Random('01/01/2016','01/05/2016')
- Random(date '2016-01-01', date '2016-05-01')
- Random((to_date('01/01/2016','DD/MM/YYYY'),to_date('01/05/2016','DD/MM/YYYY'))
- Random(SQL(to_date('01/01/2016','DD/MM/YYYY')),SQL(to_date('01/05/2016','DD/MM/YYYY')))

Can anyone help me? How can I set min and max value for a date in Random function?

Regards.
 
Last edited:
You can use the following syntax:

random(01/01/2016, 01/05/2016)

It's a bit odd that the quotes are not allowed.

Also note that the date format must match your client settings (windows format or as overruled in the NLS preferences).

An alternative:

SQL(trunc(sysdate + dbms_random.value * 364))

This will generate random dates between the current date and 364 days later.
 
Thanks for your answer!

Now it's working fine. It's really a bit odd not to use quotes. :crazy:

I think Data Generator is a good tool but it's missing a big set of examples of any of the functions available. At least in my case, I am discovering how things works by try and error.
 
Back
Top