I am new in Python.My datetime parameter is 2020-03-20T04:00:00.000Z
. How can I convert it to datetime & how can separate in date & time.
My code spinet are bellow:
schedule_time = models.DateTimeField() #This is my model code
My view code for queryset are:
def get_queryset(self):
queryset = AppointmentSerial.objects.all()
status = self.request.query_params.get('status')
schedule_time = self.request.query_params.get('schedule_time')
if not status:
queryset = queryset.exclude(status="DELETE")
if schedule_time:
dateTime = datetime.datetime.strptime(schedule_time, "%Y-%m-%d %H:%M:%S")
date = datetime.datetime.strptime(dateTime, "%Y-%m-%d %H:%M:%S").strftime("%Y,%m,%d")
time = datetime.datetime.strptime(dateTime, "%Y-%m-%d %H:%M:%S").strftime("%H:%M:%S")
if time == '00:00:00':
queryset = queryset.filter(schedule_time_date=datetime.date(date))
else:
queryset = queryset.filter(schedule_time=schedule_time)
return queryset
Also how can I query by date value of a datetime field when time is 0 ?