Igor's Blog

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.
sqldev_ddl.png


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:
 ISO 8601 Date
2017-05-14T18:16:01.001Z


In my case, as seen above, I was storing the date, time and fractional seconds. The time component was in the UTC time zone.

MySQL

To produce the above with MySql date and time functions the format string looked like this:
 MySQL ISO 8601 format string
%Y-%m-%dT%H:%i:%s.%fZ




SQLite

Moving to SQLite date functions, the format string became:
 MySQL ISO 8601 format string
%Y-%m-%dT%H:%M:%fZ


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, SQLite or any other database or programming language.

-i

comments powered by Disqus
Other posts you may like...
Programming, DIY, Games, Hacks, and Tech

Recent Blog Posts

Converting a CSV file containing commas in quotes to a pipe separated file using Awk and Bash

How to get Facybox gallery popup to work for images with dynamic URLs

jQuery UI Photoboxr plugin updated to version 0.2

Learn How to Add Disclaimer to All Outgoing Emails in Office 365

How to securely host your web site for free with Google Cloud and CloudFlare (part 3)

How to securely host your web site for free with Google Cloud and CloudFlare (part 2)

How to securely host your web site for free with Google Cloud and CloudFlare (part 1)

Beware of the subtle difference in date format strings between MySQL and SQLite

Postman reporting Unexpected 'N' error in response body

Adding extra shelves to the Ikea Detolf display cabinet

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
300 George St Blogumentary

My Online Tools

UUID to OID Converter
Guru JSON-RPC Tester
Extrudifier Object Designer
Travel µBlog

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me for more great content!
     
Don't show this again