Skip to content
Advertisement

How can I generate a random timestamp appended to getdate() in SQL Server?

The following sql select generates the current date and time:

which looks like:

I’d like to use getdate() (or an equivalent alternative) to continue getting the current date but I’d like to randomize the time component. I am having trouble finding a workable solution within a select statement.

Any suggestions?

Advertisement

Answer

here is another way if you need to have random time for each row:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement