I've been working on a SQLite
backend for my Travel µBlog
application when I came to the part that needed to deal with date/time formats. I was transitioning from a pure MySQL
backend and learned that even though SQLite
uses a very similar date/time format string, there are some subtle differences that can trip you up.
The date/times that I was wanting to deal with were in the ISO 8601
format. Specifically, this is what a sample date/time string would look like:
In my case, as seen above, I was storing the date, time and fractional seconds. The time component was in the UTC
To produce the above with MySql date and time functions
the format string looked like this:
Moving to SQLite date functions
, the format string became:
On the most part the format strings were similar. In fact the date component of the format string was identical. The time component was different however and this is where I tripped up initially. With SQLite
, the 'fractional seconds' field was represented by a single substitution (%f)
instead of two as used in MySQL (%s.%f)
So lesson learned! It's definitely worthwhile reading documentation before making any assumptions about date/time format strings, whether it be for MySQL
or any other database or programming language.
Hope you found this post useful...
...so please read on! I love writing articles that provide beneficial information,
tips and examples to my readers. All information on my blog is provided free of
charge and I encourage you to share it as you wish. There is a small favour I ask in return however -
engage in comments below, provide feedback, and if you see mistakes let me know.
If you want to show additional support and help me pay for web hosting and
domain name registration,
donations, no matter how small, are always welcome!
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...