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 8138707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:34:53+00:00 2026-06-06T11:34:53+00:00

Is there a built-in function that converts a datetime.date object into a datetime.datetime object

  • 0

Is there a built-in function that converts a datetime.date object into a datetime.datetime object with 0’s for the missing stuff? For example, suppose

tdate = datetime.date(2012,1,31)

I want to write something like either of these

tdatetime = datetime.date.datetime()
tdatetime = datetime.datetime(tdate)

and I want the output to be

datetime.datetime(2012, 1, 31, 0, 0)

But neither works. There is a builtin function to go from datetime.datetime to datetime.date, but I’m looking for the reverse operation.

One very poor solution would be to write:

datetime.datetime(tdate.year(), tdate.month(), tdate.day(), 0, 0)

I specifically want to avoid this bad way of doing it.

I’ve already written my own small function to do this, but I think it should be provided in the module. It’s cluttering up some system-wide imports to use my function. It’s workable, just not very Pythonic.

I’m just asking to see if anyone knows whether there is an efficient way to do it using only datetime module functions.

  • 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-06-06T11:34:54+00:00Added an answer on June 6, 2026 at 11:34 am

    Use .combine(date, time) with an empty time instance:

    >>> import datetime
    >>> tdate = datetime.date(2012,1,31)
    >>> datetime.datetime.combine(tdate, datetime.time())
    datetime.datetime(2012, 1, 31, 0, 0)
    

    If you like to use a constant instead, use time.min:

    >>> datetime.datetime.combine(tdate, datetime.time.min)
    datetime.datetime(2012, 1, 31, 0, 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a built-in php function that converts number of seconds to military time?
Is there a built-in function that would convert a color by name into its
Firstly, I was wondering if there was some kind of built in function that
Is there a built-in function for converting a string array into a dictionary of
i try to build a function that converts every date to a timestamp. JS
Is there some kind of built-in method or a simple function that will convert
Is there anyway I can build a Select statement that uses the Contains function?
Is there a built-in function for PHP for me to check whether two arrays
Is there a built-in function for this in Python 2.6? Something like: clamp(myValue, min,
Is there any built-in function in Python3/Numpy which filters an array and returns indices

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.