[Fixed]-Convert datetime retrieved from solr to only hours and minutes in django view

1👍

The date template filter will only work if venue_closing_time is a datetime object. If you just pass it a string (as it seems you are doing) then it will not work. In that case you need to parse the string first, e.g:

from django.utils.dateparse import parse_datetime

venue_closing_time = parse_datetime(data['venue_closing_time'])

If you pass that to the template, then your date filter will work as expected.

This would be easier if you were using a Solr library that converts the data obtained from Solr into appropriate Python representations in the first place (e.g., pysolr).

Leave a comment