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

  • SEARCH
  • Home
  • 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 6978775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:47:59+00:00 2026-05-27T17:47:59+00:00

A user is specifying an hour and minute in my interface. I’d like to

  • 0

A user is specifying an hour and minute in my interface. I’d like to attach the current date to a datetime object in Python.

First I tried this:

a = datetime.strptime("8:30pm", "%I:%M%p")
print a

But this yields:

1900-01-01 20:30:00

Then I tried:

b = date.today()
a = datetime.strptime(str(b.year) + "-" + str(b.month) + "-"
                      + str(b.day) + " 8:30pm", "%Y-%m-%d %I:%M%p")

This works, but it’s ugly; surely there is a better way?

  • 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. Editorial Team
    Editorial Team
    2026-05-27T17:48:00+00:00Added an answer on May 27, 2026 at 5:48 pm

    Yes, use datetime.datetime.combine:

    import datetime
    a = datetime.datetime.strptime("8:30pm", "%I:%M%p")
    today = datetime.datetime.today()
    
    result = datetime.datetime.combine(today.date(), a.time())
    
    # result == datetime.datetime(2011, 12, 25, 20, 30)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two devise models: User and Member As such, I'm specifying authentication keys
User Story: Action for Facebook that has open graph object. For this I need
User first_name: Johnny age: 15 Car name: Mazda Car name: BMW I would like
From a program, I created a H2 database without specifying any user or password
I have user input strings specifying the cost of an event (eg: $4 for
While using uiimagepicker, is there any way of specifying which user created album the
In order to specify some things first: The user should be able to create
The user customizes a library template class by defining a class specifying the desired
The documentation of method context.getBean(name, user) says Allows for specifying explicit constructor arguments /
Is there any way to change the default font (Portable User Interface) used by

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.