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

Kierk

The following sql select generates the current date and time:

select
Getdate() AS DueDate

which looks like:

2021-02-06 10:16:35.340

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?

eshirvana

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

SELECT
   DATEADD(SECOND ,RAND(CHECKSUM(NEWID())) * 86400,CONVERT(datetime,CONVERT(varchar(8),GETDATE(),112))) 
FROM tablename

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I generate a random timestamp in the next 5 days in Python?

how to generate a random timestamp in java?

How can I generate JSON results in older SQL Server versions?

How can I generate random alphanumeric strings?

How can I generate random shades of an RGB?

How can I generate random items with conditions?

How do I generate random number with a range X times in SQL SERVER

Generate random number (SQL Server)

How can I get a random plot of ellipses to be created using createElementNs, and be appended within a specific place of an svg?

how to compare date with GETDATE() in sql server 2008

SQL Server How can we write a sql function which returns the records where getdate() is between FromDate and Todate

How to Generate Alphanumeric Random numbers using function in SQL Server 2008

How to generate 100000 no repeat random numbers in SQL SERVER2008

How can i change attributes of appended <p> throught appended <button>

How can I manage to have an auto-insert timestamp value in my table in SQL-Server?

SQL: How can I generate a time series from timestamp data and calculate cumulative sums across different event types?

How can I generate a random int using the "crypto/rand" package?

How can i generate random char from variable

How can I generate pseudo-random "readable" strings in Java?

How can I generate a random number every x amount of months?

How can I generate random graphs with test.check?

JS - How can I generate a long random number?

How can I generate random number in specific range in Android?

How can I generate a random sequence of elements from a list in Haskell?

How can I generate random code using SuiteScript

How can I generate a random number within a range but exclude some?

How can I generate a "random constant colour" for a given string?

How can I generate different random values in Haskell?

How can I generate random (int) values with specific size and mean?

TOP Ranking

HotTag

Archive