When I am using a Python object, I get:
JavaScript
x
2
1
2018-05-18 08:38:58+00:00
2
This is not the format I need. We need to convert to this data format:
JavaScript
1
2
1
2018-05-18 08:38:58
2
How can I convert this in Python/Django?
Example:
JavaScript
1
2
1
datetime.datetime.strptime('2018-05-18 10:05:06', "%Y-%m-%d %H:%M:%S")
2
It’s working fine, but how can I pass 2018-05-18 10:05:06 as database but database giving?
JavaScript
1
2
1
2018-05-18 08:38:58+00:00
2
JavaScript
1
3
1
infoDevice = Device.objects.get(user_id=user.id)
2
newDate = Device.last_notification_time
3
It’s giving 2018-05-18 08:38:58+00:00.
How can I check date as per 2018-05-18 08:38:58?
Advertisement
Answer
Now I have implemented code for Python changes. Now it’s working. We need to just change the time setting.
Get any date from the database and change as required.
JavaScript
1
6
1
newDateFor = str(info.dbdatetime)
2
new_dt = newDateFor.split('+')[0]
3
newDate = datetime.datetime.strptime(new_dt, "%Y-%m-%d %H:%M:%S")
4
a = datetime.datetime.now().replace(microsecond=0)
5
b = newDate
6
Implement any other functionality as per changes.