Igor's Blog
Programming, DIY, Games, Hacks, and Tech

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

Recent Blog Posts

A hack to create an uber jar with the Maven Shade Plugin using local jar files

Is it worth it? Apple USB-C Digital Multi AV adapter vs a cheap eBay clone

Running X11 graphical applications after changing to another user using 'sudo su'

How to stop Facebook using ad images as post sharing thumbnails

Picking lists for Atari Lynx capacitor replacement kits

Performance - 2012 Retina MacBook Pro vs 2017 MacBook Pro

Look and feel - 2012 Retina MacBook Pro vs 2017 MacBook Pro

Using math to work out the diameter of hard to reach water cooling pipes

How to get the unreachable shard in the Hinterlands in DragonAge Inquisition

Measy RC12 wireless 2.4Ghz keyboard touchpad review

Recent Galleries

Monument Valley 2 is released and does not disappoint

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

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
Don't forget to
me for more great articles!
Don't show this again