Method: Faker::Date.between

Defined in:
lib/faker/default/date.rb

.between(from:, to:) ⇒ Date

Produce a random date between two dates.

Examples:

if used with or without Rails (Active Support)

Faker::Date.between(from: '2014-09-23', to: '2014-09-25') #=> #<Date: 2014-09-24>

if used with Rails (Active Support)

Faker::Date.between(from: 2.days.ago, to: Date.today) #=> #<Date: 2014-09-24>

Parameters:

  • from (Date, String)

    The start of the usable date range.

  • to (Date, String)

    The end of the usable date range.

Returns:



22
23
24
25
26
27
# File 'lib/faker/default/date.rb', line 22

def between(from:, to:)
  from = get_date_object(from)
  to   = get_date_object(to)

  Faker::Base.rand_in_range(from, to)
end