0

I'd like to format the test dates generated by Bogus to dd.MM.yyyy (eg. 29.09.2022).

I've been searching for a solution but can't find anything.

I tried the following but it doesn't work:

var personData = new Faker<Person>()
    .RuleFor(
        p => p.DateOfBirth,
        f => f.Date.Past(30, DateTime.Now.AddYears(-20))
        .ToString("dd.MM.yyyy"));

Thanks in advance for any help!

Mazzmax
  • 7
  • 1
  • 4
  • https://stackoverflow.com/q/65943152/7565574 has a similar issue: so try `new Faker("de_DE");` or `new Faker("de");` – ckuri Sep 29 '22 at 16:37

1 Answers1

0

try that:

.RuleFor(c => c.Birthday, f =>
                         {
                             var pastDateTime = f.Date.PastOffset(40, DateTime.Now.AddYears(-18));
                             var result = DateTime.Parse(pastDateTime.ToString("dd.MM.yyyy"));
                             return result;
                         })

enjoy it

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '23 at 00:51