Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 134499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:37:28+00:00 2026-05-11T06:37:28+00:00

How would I generate a random date that has to be between two other

  • 0

How would I generate a random date that has to be between two other given dates?

The function’s signature should be something like this:

random_date('1/1/2008 1:30 PM', '1/1/2009 4:50 AM', 0.34)                    ^                       ^          ^              date generated has  date generated has  a random number             to be after this    to be before this 

and would return a date such as: 2/4/2008 7:20 PM

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:37:29+00:00Added an answer on May 11, 2026 at 6:37 am

    Convert both strings to timestamps (in your chosen resolution, e.g. milliseconds, seconds, hours, days, whatever), subtract the earlier from the later, multiply your random number (assuming it is distributed in the range [0, 1]) with that difference, and add again to the earlier one. Convert the timestamp back to date string and you have a random time in that range.

    Python example (output is almost in the format you specified, other than 0 padding – blame the American time format conventions):

    import random import time      def str_time_prop(start, end, time_format, prop):     """Get a time at a proportion of a range of two formatted times.      start and end should be strings specifying times formatted in the     given format (strftime-style), giving an interval [start, end].     prop specifies how a proportion of the interval to be taken after     start.  The returned time will be in the specified format.     """      stime = time.mktime(time.strptime(start, time_format))     etime = time.mktime(time.strptime(end, time_format))      ptime = stime + prop * (etime - stime)      return time.strftime(time_format, time.localtime(ptime))   def random_date(start, end, prop):     return str_time_prop(start, end, '%m/%d/%Y %I:%M %p', prop)      print(random_date("1/1/2008 1:30 PM", "1/1/2009 4:50 AM", random.random())) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 115k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would expect you to have problems with this. For… May 11, 2026 at 10:23 pm
  • Editorial Team
    Editorial Team added an answer The wiki page is always a good place to start,… May 11, 2026 at 10:23 pm
  • Editorial Team
    Editorial Team added an answer safeWrap returns a function that sets a timeout of 0ms… May 11, 2026 at 10:23 pm

Related Questions

I have an AJAX chat system that I'm working on and so far I
I need to generate a random integer between 1 and n (where n is
In Java, I have a subclass Vertex of the Java3D class Point3f . Now
I'm working on an application where users have to make a call and type

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.