Question: Is there a simple way to state that 

```
a = '2020-01-01 19:30:33.996628' 
b = '2020-01-01 19:30:34' 

```

`a` and `b` are equal. If the time resolution of `a` is changed to second, then `a` could be equal to `b`. How to implement it with code?

Answer: 
Set to next second
------------------

* Add the `timedelta` difference between `1e6` and `a.microsecond`

```
from datetime import timedelta, datetime

a = datetime.fromisoformat('2020-01-01 19:30:33.996628')

a = a + timedelta(microseconds=(1e6 - a.microsecond))

print(a)

>>> datetime.datetime(2020, 1, 1, 19, 30, 34)

print(a.strftime('%Y-%m-%d %H:%M:%S'))

>>> 2020-01-01 19:30:34

```

Set to current second
---------------------

* With `.replace(microsecond=0)`

```py
from datetime import datetime

a = datetime.fromisoformat('2020-01-01 19:30:33.996628')

print(a)

>>> datetime.datetime(2020, 1, 1, 19, 30, 33, 996628)

a = a.replace(microsecond=0)

print(a)

>>> datetime.datetime(2020, 1, 1, 19, 30, 33)

```
The function `datetime_round_s()` below rounds to the closest second (like usual rounding of numbers):

```python
import datetime

def datetime_round_s(date_time: datetime.datetime) -> datetime.datetime:
    return (date_time + datetime.timedelta(microseconds=5e5)).replace(microsecond=0)

a = datetime.datetime.fromisoformat('2020-01-01 19:30:33.996628')
b = datetime.datetime.fromisoformat('2020-01-01 19:30:34')

print(a)
print(datetime_round_s(a))
print(datetime_round_s(a) == b)

```

otuput:

```none
2020-01-01 19:30:33.996628
2020-01-01 19:30:34
True

```