B
B
bQ12019-10-30 10:31:53
Django
bQ1, 2019-10-30 10:31:53

How to convert date to readable format for django queryset filtering?

How to convert a date in the Fri Oct 04 2019 00:00:00 GMT 0300 (Moscow, standard time) format, which comes as a string from the front (this is how the js plugin returns to the calendar) into a normal date that is well read in filtering?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-10-30
@bQ1

Isn't it easier for the plugin to send a timestamp than trying to parse incomprehensible formats?
send date from js
Well, or in the end use the ISO format: upon receipt
date = datetime.fromisoformat(date)

Y
Yura Khlyan, 2019-10-30
@MAGistr_MTM

datetime.strptime(date, '%a %b %d %Y %H:%M:%S %Z 0300')

But it is not clear how to deal with the remainder (0300), since it is not in the standard format (should be + or - in front). If the time is always Moscow, then the code will work correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question