php-fakerHow can I generate fake birthdays using Laravel Faker?
Using Laravel Faker you can generate fake birthdays with ease. Here is an example code block to generate a fake birthday and the output of that code:
$faker = Faker\Factory::create();
$birthday = $faker->dateTimeBetween('-50 years', 'now');
echo $birthday->format('Y-m-d');
Output example
1990-02-25
The code is composed of the following parts:
$faker = Faker\Factory::create();
- This creates a new Faker instance.$birthday = $faker->dateTimeBetween('-50 years', 'now');
- This creates a random datetime object between the range of 50 years ago and now.echo $birthday->format('Y-m-d');
- This prints out the birthday in the format of Y-m-d.
You can also customize the range of the generated birthdays by changing the parameters of dateTimeBetween()
. For more information, refer to the Faker documentation.
More of Php Faker
- How do I generate a zip file using PHP Faker?
- How can I generate a zip code using Laravel Faker?
- How can I generate fake data in XLSX format using PHP Faker?
- How do I generate a random zip code using PHP Faker?
- How can I specify the word length when using Laravel Faker?
- How do I set the locale for PHP Faker?
- How do I generate a fake year in Laravel using Faker?
- How do I check which version of Laravel Faker I am using?
- How do I generate a valid VAT number using Laravel Faker?
- How can I generate unique data with Laravel Faker?
See more codes...