Is it possible to format a date using sqlite3?

At the beginning you have the string "DDMMYYYY HHMMSS" and I want to insert the string at the end into a date field in the sqlite3 database. The program is executed in python. How can i do this?

0


a source to share


3 answers


Although ".schema" indicates that the field is a date or time field, the field is indeed a string. You can format the string anyway. If the memory serves ... they are not checked at all.



+1


a source


I believe sqlite3 does not have a DATE type, so you have to do it manually in your Python code. Either you store the date in this particular form, or convert it to a timestamp or other form.



Have a look at the datetime module and especially the function strptime

.

+1


a source


As stated in other answers, it is stored as a string. However, it will be recognized as a date if you paste it in one of the following formats

Time strings

The time string can be in any of the following formats:

 1. YYYY-MM-DD
 2. YYYY-MM-DD HH:MM
 3. YYYY-MM-DD HH:MM:SS
 4. YYYY-MM-DD HH:MM:SS.SSS
 5. YYYY-MM-DDTHH:MM
 6. YYYY-MM-DDTHH:MM:SS
 7. YYYY-MM-DDTHH:MM:SS.SSS
 8. HH:MM
 9. HH:MM:SS
10. HH:MM:SS.SSS
11. now
12. DDDDDDDDDD

      

LINK:


Date and time functions
+1


a source







All Articles