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:
    Code:
    [entrCreate] INT NOT NULL DEFAULT (strftime('%s','now') *1000)
    Make sure that the expression (strftime('%s','now') *1000) is enclosed in brackets.

    Code:
    CREATE TABLE [tablexyz](
      [IDScd2] INTEGER PRIMARY KEY AUTOINCREMENT,
      [StatCat_id] INT 
    NOT NULL DEFAULT (-1),
      [Scd_ArtName] TEXT 
    NOT NULL DEFAULT '' COLLATE NOCASE,
      [Scd_YM] TEXT NOT NULL DEFAULT '' COLLATE NOCASE,
      [Scd_SumPrc] TEXT NOT NULL DEFAULT '' COLLATE NOCASE,
      [Scd_SumAmnt] TEXT NOT NULL DEFAULT '' COLLATE NOCASE,
      [Scd_Flags] TEXT NOT NULL DEFAULT '' COLLATE NOCASE,
      [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:
    16-04-_2018_08-52-51.png
     
  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.
Loading...
  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