Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Random date in JavaScript
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
console.log(randomDate(new Date(2012, 0, 1), new Date()));
@saltarin

This comment has been minimized.

Copy link

@saltarin saltarin commented Nov 22, 2017

nice memes

@vedro-compota

This comment has been minimized.

Copy link

@vedro-compota vedro-compota commented Feb 5, 2019

thanks!

@gawdeparag

This comment has been minimized.

Copy link

@gawdeparag gawdeparag commented Jun 22, 2019

Thanks for this! Saved my day!!

@thomas-avada

This comment has been minimized.

Copy link

@thomas-avada thomas-avada commented Feb 18, 2020

Not all heroes wear capes

@Ainika-Kos

This comment has been minimized.

Copy link

@Ainika-Kos Ainika-Kos commented Dec 27, 2020

Thank you! ;)

@Alphavader

This comment has been minimized.

Copy link

@Alphavader Alphavader commented Apr 14, 2021

Thanks man!

@arthursvpb

This comment has been minimized.

Copy link

@arthursvpb arthursvpb commented Apr 21, 2021

very useful! thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment