{"id":4435,"date":"2023-11-24T15:48:19","date_gmt":"2023-11-24T15:48:19","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4435"},"modified":"2025-05-01T12:43:03","modified_gmt":"2025-05-01T11:43:03","slug":"datetime","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/database\/sqlite\/columns\/datetime","title":{"rendered":"DateTime"},"content":{"rendered":"\n<p>SQLite does not have a storage class set aside for storing dates and\/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as INTEGER, TEXT or REAL values:<\/p>\n\n\n\n<p>INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.&nbsp;<br>TEXT as ISO8601 strings (&#8220;YYYY-MM-DD HH:MM:SS.SSS&#8221;).<br>REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.<\/p>\n\n\n\n<p>Integer is best if you will want to quickly search based on datetime values, etc.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Adding a column used for DateTime to a table<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE IF NOT EXISTS tbl1(id int primary key, CreatedDateTime INTEGER);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Adding a DateTime value to a column being used for DateTime<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    db1cursor.execute(\"\"\"INSERT INTO my_table(\n                        CreatedDateTime,\n                        CameraId\n                    ) VALUES (\n                        datetime('now'),    #This gives UTC DateTime\n                        1\n                    )\"\"\");\n\n# datetime('now')        &lt;&lt;&lt;Use for UTC\n# datetime('now','localtime');        &lt;&lt;&lt;Use for local time<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SQLite does not have a storage class set aside for storing dates and\/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as INTEGER, TEXT or REAL values: INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.&nbsp;TEXT as ISO8601 strings (&#8220;YYYY-MM-DD HH:MM:SS.SSS&#8221;).REAL as Julian [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[354],"tags":[],"class_list":["post-4435","post","type-post","status-publish","format-standard","hentry","category-columns"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4435"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4435\/revisions"}],"predecessor-version":[{"id":4920,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4435\/revisions\/4920"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}