V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
andmspy
V2EX  ›  数据库

sqlite3 函数嵌套疑问

  •  
  •   andmspy · Feb 22, 2018 · 1816 views
    This topic created in 2989 days ago, the information mentioned may be changed or developed.

    请教一下,想每次批量处理提取的数据都是当前日期的数据,可以就是不能提取出来,也没有报错,就是不知道为什么

    select date from worker where date=(select date('now'))

    背景: 表:worker 字段:date 格式:2018/2/22

    但是如果修改成 select date from worker where date=‘ 2018/2/22 ’ 这样就可以成功提取出来,用函数就不行了。

    4 replies    2018-03-06 23:19:15 +08:00
    Dic4000
        1
    Dic4000  
       Feb 22, 2018
    试试:select date from worker where date=Date('now')
    alpenstock
        2
    alpenstock  
       Feb 23, 2018
    sqlite date() 函数默认的格式是 2018-02-22,不是 2018/2/22
    可以用
    select date from worker where date=(select strftime('%Y/%m/%d','now'));
    或者
    select date from worker where date= strftime('%Y/%m/%d','now');
    alpenstock
        3
    alpenstock  
       Feb 23, 2018
    SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

    TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
    REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
    INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

    参考自 http://sqlite.org/datatype3.html
    andmspy
        4
    andmspy  
    OP
       Mar 6, 2018
    谢谢,谢谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2508 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 06:40 · PVG 14:40 · LAX 23:40 · JFK 02:40
    ♥ Do have faith in what you're doing.