Search code examples
tarantool

Store date and time in tarantool


Suppose I need a field in tuple which should be date with time. Tarantool doesn't support date and time types out of the box.

I see two solutions:

  1. Store date and time as string and parse it.
  2. Store date and time in epoch seconds and convert it when needed.

What is the best solution to work with dates and times in Tarantool?


Solution

  • You should use UNIX time format (seconds since the beginning of the UNIX epoch) for two reasons: - it's compact - the desired ordering can be achieved with TREE index on 'unsigned' type. If you deal with multiple time zones, it's best to convert to UNIX time before inserting into the database, and store the time zone in a separate field.