Basel J. Hamadeh Basel J. Hamadeh -4 years ago 251
jQuery Question

Jquery Datetimepicker to Python Datetime

I have below jQuery Datetimepicker

<input type="text" name="datetime" id="datetime">

controlType: 'select',
oneLine: true,
timeFormat: 'hh:mm tt'

I'm sending the date as AJAX POST request to Django:

const starts = $('#datetime').val();
type: 'POST',
url: '/booking/new/',
data: {
starts: starts,

In Django i get the value:

if request.method == 'POST':
starts = request.POST.get('starts')
object.starts = datetime.strptime(starts, '%x %I:%M %p')

I get the following error:

ValueError: time data '11/12/2016 12:00 am' does not match format '%x %I:%M %p'

I tried different formats but I can't find the correct one. Can i produce the format from the string value some how?

Answer Source

You can define default datetime format like this follow some rule

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download