How to archive the following...

i need to pass two variable date which comes as long format and apply this variable in a subquery using raw sql django

```
def duplicatephoneno(request):

    cursor = connection.cursor()
    payload = json.loads(request.body.decode('utf-8'))
    print(payload)
    if payload:
        startdate=payload['from']
        enddate=payload['to']
        with connection.cursor() as cursor:
            cursor.execute(MYSQLdb.escape_string("SELECT * FROM `allergy` WHERE `allergy`.`patient_n_key` IN (SELECT `patient_masters`.`patient_n_key` FROM `patient_masters` WHERE `patient_masters`.`created_on`between %s AND %s)",[startdate], [enddate]))
            row = dictfetchall(cursor)
            patientuser=serializers.serialize('json', row)
        return HttpResponse(patientuser, content_type='application/json;charset=utf8')

```