27

How do I get future dates with:

https://github.com/fzaninotto/Faker#fakerproviderdatetime

dateTime($max = 'now')  

i.e. what should the $max value be for datetime in the future

Angad Dubey
  • 5,067
  • 7
  • 30
  • 51

4 Answers4

58

You can pass strtotime string conditions to $faker->dateTimeBetween().

//ranging from today ending in 2 years
$faker->dateTimeBetween('+0 days', '+2 years')

//ranging from next week ending in 1 month
$faker->dateTimeBetween('+1 week', '+1 month')

//ranging from next sunday to next wednesday (if today is wednesday)
$faker->dateTimeBetween('next sunday', 'next wednesday')

see http://php.net/manual/en/function.strtotime.php for a full list of string usages and combinations.

mshaps
  • 884
  • 1
  • 6
  • 10
40

Try passing a unix timestamp for $max:

$unixTimestamp = '1461067200'; // = 2016-04-19T12:00:00+00:00 in ISO 8601

echo $faker->dateTime($unixTimestamp);

echo $faker->date('Y-m-d', $unixTimestamp);

// for all rows 
$faker->dateTimeBetween('now', $unixTimestamp);

Or pass a strtotime timestring to $faker->dateTimeBetween():

// between now and +30y
$faker->dateTimeBetween('now', '+30 years');
dipenparmar12
  • 3,042
  • 1
  • 29
  • 39
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
3

To get date for a tomorrow. We can use this.

$faker->dateTimeBetween('now', '+01 days');

Or for future date, we can use php strtotime function as @mshaps already mentioned.

Pyae Sone
  • 1,574
  • 2
  • 14
  • 18
0

Try this:

$faker -> dateTimeThisDecade($max = '+10 years')
HassanUsman
  • 1,787
  • 1
  • 20
  • 38