How can I generate random dates within a range?
c#, datetime
Solution
void Main()
{
Console.WriteLine(DateTime.UtcNow.AddDays(new Random().Next(90)));
}
This will add a random amount of days to the start date, essentially ending up with a random date.
Problem
I am automating an application where records can be opened between specified date ranges. I know that I can create an array that randomly picks a number in my array, such as: ``` DateTime.Now.AddDays(90).ToString("MM/dd/yyyy") ``` However, I would like to know if there is a better way to go about this. Please help! Thanks.