Last active
September 6, 2023 18:07
-
-
Save vordan/ba944648300efcbc4cfc240a6b21af13 to your computer and use it in GitHub Desktop.
Generate random date between two dates in MySQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
concat(round(rand() * 10000), | |
round(rand() * 10000), | |
round(rand() * 10000), | |
round(rand() * 10000) | |
) as rnd | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select date_format( | |
from_unixtime( | |
rand() * | |
(unix_timestamp('1967-11-13 16:00:00') - unix_timestamp('1990-11-13 23:00:00')) + | |
unix_timestamp('1990-11-13 23:00:00') | |
), '%Y-%m-%d %H:%i:%s') as datum_roden | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
concat( | |
'0', floor(rand() * (79 - 70 + 1)) + 70, '/', | |
floor(rand() * 401) + 100, '-', | |
floor(rand() * 401) + 100 | |
) | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generically, FLOOR(RAND() * (<max> - <min> + 1)) + <min> | |
generates a number between <min> and <max> inclusive. | |
-- Between 17 and 44 | |
select floor(rand() * (44 - 17 + 1)) + 17; |
ZsoltDM
commented
Sep 6, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment