How to get future date in Faker
Solution 1
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');
Solution 2
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.
Solution 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.
Related videos on Youtube
Angad Dubey
I am a full stack developer with experience in building applications using enterprise frameworks, setting up deployment pipelines, crafting relational database schemas, ensuring automated test coverage across the board, and implementing modern, responsive UI designs. Development Lifecycle I have experience working with product stakeholders, providing technical context to discussions, particularly during ideation. I regularly participate in development planning discussions working with the product management team as well as development team. In the role of Lead Developer, I have been involved in and responsible for managing deliverables of addressing existing issues or shipping new features, while keeping myself up to date with the technological trends and improvements, so that I may prevent the product and/or internal development tools and practices from becoming obsolete. Modernizing Legacy Applications There are quite a few legacy applications out in the wild and I have seen my share of them.I have managed to apply most of the 12 factors (https://12factor.net/) of modern application development to them, making them maintainable and reducing the need to keep development resources occupied with constantly fire fighting bugs and issues. To achieve this, I have worked closely with the product management team and the stakeholders, to get a bird's eye view of their needs and to also convey to them the costs and benefits of modernizing efforts.
Updated on May 08, 2020Comments
-
Angad Dubey almost 4 years
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
-
Alex Chorry almost 9 yearsmagic word 'tomorrow' should be enough :)
-