Skip to main content
Question Protected by Ry-
removed the part about the question being silly
Source Link
avpaderno
  • 30k
  • 17
  • 81
  • 95

Silly question, but isIs there a built-in method for converting a date to a datetime in Python, ie.for example getting the datetime for the midnight of the dategiven date? The opposite conversion is easy -: datetime has a .date() method. 

Do I really have to manually call datetime(d.year, d.month, d.day)  ?

Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day)  ?

Is there a built-in method for converting a date to a datetime in Python, for example getting the datetime for the midnight of the given date? The opposite conversion is easy: datetime has a .date() method. 

Do I really have to manually call datetime(d.year, d.month, d.day)?

Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day) ?

Edit: and the winner is:

datetime.combine(d, time())

Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day) ?

Edit: and the winner is:

datetime.combine(d, time())

Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day) ?

added 67 characters in body
Source Link
EMP
  • 62.7k
  • 57
  • 168
  • 223

Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day) ?

Edit: and the winner is:

datetime.combine(d, time())

Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day) ?

Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day) ?

Edit: and the winner is:

datetime.combine(d, time())
Source Link
EMP
  • 62.7k
  • 57
  • 168
  • 223
Loading