I am trying to generate random DateTime instances using the DateTime Constructor (Int64) as below:
string date = new DateTime(ticks).ToString("dd/mm/yyyy")
The ticks are random numbers between 633999744000000000 (2010/01/25 in ticks) and 635578272000000000 (2015/01/26 in ticks).
Output:
date ticks
---- -----
13/37/2013 634963486624182148
27/58/2010 634158395314391599
20/49/2011 634442033950650720
21/15/2013 634943637106398216
10/30/2014 635380290170226984
10/07/2012 634881676490509687
27/43/2012 634711201999181055
15/13/2012 634726699845971038
01/59/2010 634241843691014848
However, the above results do not represent valid instances in time.
How can I generate random DateTime instances that represent valid dates using ticks?
The
DateTimevalues are fine – it’s your formatting that’s wrong. You wantMMrather thanmmin your format string.mmis for minutes.See “custom date and time format strings” in MSDN for more details.