Issue
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?
Solution
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)
Answered By - Thành Nguyễn Lý
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.