Home > Blockchain >  how to check isinstance for date in django python
how to check isinstance for date in django python

Time:06-23

I have date data in variable date_var as

from django.db import models
from datetime import datetime

class Model:
  created_date    =   models.DateTimeField

date_var = model.created_date.date()

however when I check isinstance of c with datetime or with models.DateTimeField it returns false

isinstance(date_var,datetime)
// False

isinstance(date_var,models.DateTimeField)
// False

what is the way to check if c is instance of date?

CodePudding user response:

In your case, type of date_var is date not datetime.

If you want to check type date, you can do like below

from datetime import date

isinstance(date_var, date)

  • Related