T
T
trytrytry2013-12-21 19:41:32
Django
trytrytry, 2013-12-21 19:41:32

How to write date to db?

An error occurs when trying to write a date to the model and then save it.

new = Raspisanie("2013-01-01")
new.save();

The following error occurs:
invalid literal for int() with base 10: '2013-01-01'

Though in model the data type costs DAteField.
With what can be connected?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
webbus, 2013-12-21
@webus

You are trying to write the string "2013-01-01", not the date.
For starters, read about the datetime type in python

S
SilentSokolov, 2013-12-21
@SilentSokolov

If everything is correct the DateField expects a datetime object as webus mentioned.
About datetime in general, you can also find about strptime there if you directly need to create a date from a string.

T
trytrytry, 2013-12-21
@trytrytry

I just take from the html calendar and it is already in the form of a string. could you tell me how to parse it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question