title: SQL Server : random date in specific range (including random hours, minutes,...)
body: <p>I would like to create a random date for a SQL Server update query. I found a lot examples for random days or something similar but I couldn't find something which creates a random date with random date, hours, minutes, seconds AND milliseconds.</p>
  
  <p>This is what I use to create the date randomly but it always gives me 00 as hour, minute, seconds and milliseconds and I don't know how I can randomize them as well.</p>
  
  <p>This is my query:</p>
  
  <pre><code>declare @FromDate date = GETDATE()-2
  declare @ToDate date = GETDATE()-1
  
  UPDATE ACCOUNTS
  SET dateFinished=
  dateadd(day, rand(checksum(newid())) * (1 + datediff(day, @FromDate, @ToDate)), @FromDate)
  </code></pre>