Print Thread
Data Generator: How to generate random dates between min and max?
#53511 05/05/16 04:09 PM
Joined: Oct 2007
Posts: 18
Spain
ifernan Offline OP
Member
OP Offline
Member
Joined: Oct 2007
Posts: 18
Spain
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 by ifernan; 05/05/16 04:11 PM.
Re: Data Generator: How to generate random dates between min and max?
ifernan #53513 05/06/16 09:20 AM
Joined: Aug 1999
Posts: 22,221
Member
Offline
Member
Joined: Aug 1999
Posts: 22,221
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.


Marco Kalter
Allround Automations
Re: Data Generator: How to generate random dates between min and max?
Marco Kalter #53515 05/06/16 09:56 AM
Joined: Oct 2007
Posts: 18
Spain
ifernan Offline OP
Member
OP Offline
Member
Joined: Oct 2007
Posts: 18
Spain
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.


Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.028s Queries: 15 (0.008s) Memory: 2.5037 MB (Peak: 3.0394 MB) Data Comp: Off Server Time: 2024-05-21 21:58:48 UTC
Valid HTML 5 and Valid CSS