Obviously I can get the date and time from datetime.datetime.now()
, but I don't actually care about the seconds or especially microseconds.
Is there somewhere I can easily get Date+Hour+Minute?
Obviously I can get the date and time from datetime.datetime.now()
, but I don't actually care about the seconds or especially microseconds.
Is there somewhere I can easily get Date+Hour+Minute?
You can clear down the second and microsecond component of a datetime value like so:
dt = datetime.datetime.now()
#Now get rid of seconds and microseconds component:
dt = dt.replace(second=0, microsecond=0)
This would allow you to compare datetimes to minute granularity.
If you just want to print the date without a second/microsecond component, then use the appropriate format string:
dt = datetime.datetime.now()
print dt.strftime("%Y/%m/%d %H:%M")
>>> '2012/12/12 12:12'