How to get only time in models
If you have an object datetime
in your template foo
use:
{{ foo|time:"H:i" }}
Take a look at the time
filter documentation . You are not limited "H:i"
, there are many options for formatting objects datetime
.
If for some reason you want to do this right in your model (which is probably not where it is), use datetime
strftime
- look at the appropriate one.
For example, again assuming an object datetime
named foo
:
hour = foo.strftime("%H:%M")
source to share