4

I'm trying to access time.ctime() in order to make some simple boolean operations. I found this procedure:

datetime.datetime.strptime(time.ctime(), "%a %b %d %H:%M:%S %Y")

Which gives me this:

datetime.datetime(2017, 10, 5, 17, 7, 51)

How can I access time.ctime() date and time separate so I could get:

datetime.date(2017, 10, 5)

and

datetime.time(17, 7)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
hernanavella
  • 5,462
  • 8
  • 47
  • 84

1 Answers1

2

You can use the date() and time() methods to extract them:

dt = datetime.datetime(2017, 10, 5, 17, 7, 51)
d = dt.date()
t = dt.time()
Mureinik
  • 297,002
  • 52
  • 306
  • 350