filter date for a specific hour and minute
Try something like this:

for i in dates:
    if i.hour == selected_hour:
        print i
    elif i.hour == (selected_hour - 1) % 24 and i.minute &gt; 45:
        print i
    elif i.hour == (selected_hour + 1) % 24 and i.minute &lt;= 15:
        print i


The biggest technique I used to condense your code basically was "Don't repeat yourself"! You have a lot of redundant if statements in your code which can be simplified.

Another thing that makes my code more understandable is that it's flat, not nested. Ideally, you'd want to minimize the number of logic branches.

Edit: As @Dougal mentioned, my original code wouldn't work on the special case of midnight. I added in a modulus operator on my two elif conditions so that the selected_hour test wraps in a 24 digit circle, just like real time.