Android Code Snippet Create SQLite field with default "date now" in milliseconds

Discussion in 'Code Snippets' started by fredo, Apr 16, 2018.

  1. fredo

    fredo Active Member Licensed User

    DDL code:
    [entrCreate] INT NOT NULL DEFAULT (strftime('%s','now') *1000)
    Make sure that the expression (strftime('%s','now') *1000) is enclosed in brackets.

    CREATE TABLE [tablexyz](
      [StatCat_id] INT 
      [Scd_ArtName] TEXT 
      [Scd_ArtIdx] INT NOT NULL DEFAULT (-1),
      [entrCreate] INT 
    NOT NULL DEFAULT (strftime('%s','now') *1000) ,
      [entrChange] INT NOT NULL DEFAULT (strftime('%s','now') *1000)
    At each new row insert the fields [entrCreate] and [entrChange] are automatically filled with the Datetime.Now equivalent in epoch format:
  2. yiankos1

    yiankos1 Active Member Licensed User

    I expiriment this code right now, if i ORDER BY entrCreate ASC on a SELECT query, should it work correctly?
  3. fredo

    fredo Active Member Licensed User

    Yes. In the Example the fieldtype is "INT", so it can be handled like a normal numeric value in ORDER, GROUP, WHERE, ...
    DonManfred and yiankos1 like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice