So I have a table in MySQL which stores a name and a date. I want to write a query that gets the closest date to a certain date I have determined. For example, I have:

```
x = datetime(2022, 01, 01)

```

This:

```
query = "SELECT date_ FROM set_payment7777 GROUP BY name"
mycursor.execute(query)
for cursor in mycursor:
    print(cursor)

```

is currently printing all the dates from the table grouped by name. I want to add something to make it print all the dates for each name that is closer to the variable x.

For instance, if we have the entries in the table: "06-06-2021, James" also "06-07-2021, James" and "04-04-2021, Helen" also "05-04-2021, Helen" it should print: 06-07-2021 and 05-04-2021.

I hope you understand.