phpfaker

How to get future date in Faker


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


Solution

  • 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');