Monday, June 28, 2010

How to generate a random date between two known dates in javascript?

function getRandomDate(from, to) {
    if (!from) {
        from = new Date(1900, 0, 1).getTime();
    } else {
        from = from.getTime();
    }
    if (!to) {
        to = new Date(2100, 0, 1).getTime();
    } else {
        to = to.getTime();
    }
    return new Date(from + Math.random() * (to - from));
}
The Code above not tested yet, no guarantee it's runnable...

7 comments:

Unknow said...

Nice knowledge gaining article. This post is really the best on this valuable topic. 统计代写

Air Cargo Packers And Movers said...

Hire only an experienced and reliable company which has the capability to do the work efficiently.Packers and Movers Delhi You can check their previous works to confirm the things more deeply. Best Packers and Movers Delhi Check the testimonials on the company’s website. Testimonials are great to understand the company’s ability to tackle the problematic situations.Packers and Movers Delhi Experience does not matter when you have good skills. But, when the thing is about your important personal items, you should not hand them to any unprofessional hands.Movers And Packers Delhi

Yakshita said...

Thanks for Sharing such an amazing article. Keep working... Your Site is very nice, and it's very helping us.. this post is unique and interesting, thank you for sharing this awesome information

SC ST Udyami Yojana| Udyami Yojana

Yakshita said...

Your blog is filled with unique good articles! I was impressed how well you express your thoughts.

Practically App | Practically App Download | Practically App for PC

Darren Demers said...

Hire only an experienced and reliable company which has the capability to do the work efficiently.Packers and Movers Delhi You can check their previous works to confirm the things more deeply. mens bracelets australia , mens bracelets chile , Best Packers and Movers Delhi Check the testimonials on the company’s website. Testimonials are great to understand the company’s ability to tackle the problematic situations.

Debbie Brinkmann said...

Your article seemed very informative. You provided me with valuable information. Thanks for sharing this. I recently published an article on this topic. This article covers the new Click Checker tool that you should use when using Fast Click. In this article, we will explain in detail how to use the check clicks tool per second. Click here for more information Kohi Click Test - Best CPS Test!. Tell me what you think.

nancyharriet said...

Business Assignment has various topics such as business statistics, business reports, business marketing strategy, business decision-making, and many more. In order to provide the best business assignment help an expert needs in-depth knowledge about the subject and then they can satisfy the customers. Global Assignment Expert always offers high-quality content from introduction to conclusion with well-structured assignments.