Random DateTime in the range (C#)

So You need a random DateTime value in some range, and C# Random class does not provide Random.NextDateTime(from, to). Here’s a simple solution for this problem…

 

As this method is written as an extension method to Random class, you’ll be able to use it just as a static Random class method (Random.NextDateTime(startDateTime, endDateTime). For example…

 

Leave a Reply

Your email address will not be published. Required fields are marked *