vendredi 4 février 2022

Random date and time C# from last week

I am trying to generate a start and end date time from last week.

so if today is 04/02/2022 then I need a random date and time from last week so it could be

Start 02/02/2022 10:00

End 02/02/2022 10:30

notice that the end time is 30 mins always.

I can get the date part working by using this

Random gen = new Random();
var start = DateTime.Now.AddDays(-7);
int range = (DateTime.Today - DateTime.Today.AddDays(-7)).Days;

var result = start.AddDays(gen.Next(range));



Aucun commentaire:

Enregistrer un commentaire