Random Date in Range

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

How can I get a random date in a certain date range? For example:

Get random date between 27-02-2007 and 30-09-2008?

Thanks,
Miguel
 
01: You can create a TimeSpan by subtracting the earlier date from the later
date.
02: Use Random to get a random number 0..(theTimeSpan.TotalDays)
03: return LesserDate.AddDays(thatRandomNumber);

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Random Order of IEnumerable 5
Random Record 17
IEnumerable Null 4
Random Record. Alternative. 6
Validate DateTime 3
Random String Extension. How to get all available characters? 10
Random Extension 10
Random String 6

Back
Top