Hello. It was necessary to generate a random date from current to specific. The Data :: Random module has similar functionality, but does not work complaining about the wrong range.

max date is later than min date

Code identical to the example from the page of the module on cpan

use Data::Random qw(:all); my $date = rand_date( min => 'now', max => '2008-9-21' ); print $date; 

Perhaps there are some alternative options? Modules?

  • The error is strange, since the maximum date and must be greater than the minimum. Maybe min date is later than max date? Then the error is explainable: your max data is in the past, 9 years ago because of now . Try to specify the minimum date for the test exactly and less than the maximum. - Mark Shevchenko
  • one
    you seem confused min and max. you give an interval from the past to the current date, then max is just now, and min 2008 is Mike
  • The Data :: Random module describes this functionality, I need to generate a date from today's date to any date in the past. - Evgeniy A

1 answer 1

No matter how the error message looks there, this is clearly not 2008, and the appearance of an error is logical. Set max later. This line works for me:

 my $date = rand_date( min => 'now', max => '2020-9-21' );