Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 231
    Not a silly question; date objects should have a .datetime() method; what's silly is that they don't have such a method. Commented Oct 14, 2013 at 3:57
  • 28
    @Zags: or datetime.from_date() constructor. Commented May 9, 2015 at 21:36
  • 17
    no it shouldn't a date is a subset of datetime (it's even in the name). It's unambiguous what the date is from a datetime. But the other way round, a date is a block of 24h (usually), so it can have many datetimes. What datetime would come from a date? You can't always so 00:00 because what if that time doesn't exist, like for example daylight savings skipped it. Not so easy# Commented Mar 1, 2017 at 12:33
  • 7
    @Dalore Daylight savings time is between 1am and 2am to avoid exactly the problem you are describing. Commented Jan 25, 2019 at 21:28
  • 4
    @zags it all depends on the timezone source and destination, you can have a daylight savings time change at 1am but that would correspond to a midnight change in some other timezone. and if you're programming which timezone are you using? you could very well end up trying to get a time that doesn't exist. My point still stands, adding a time to a date is not straight forward. Then you also got to consider is your new datetime also timezone aware or naive. Commented Feb 4, 2019 at 15:44