代码之家  ›  专栏  ›  技术社区  ›  Ryan Gadsdon

两个日期之间的时间(分钟)差异MySQL

  •  0
  • Ryan Gadsdon  · 技术社区  · 6 年前
    CREATE TABLE Test (
    
    id int primary key,
    Present varchar(10),
    Date date,
    Time time
    );
    
    INSERT INTO Test (id, Present, Date, Time)
    Values (1, 'Present', '2018-07-18', '10:13:55' ),
    (2, 'Present', '2018-07-18', '10:10:55' );
    

    查询:

    SELECT 
    id,
    Present,
    Date,
    Time,
    current_time AS 'Current Time',
    TIMESTAMPDIFF(MINUTE, [Time], CURRENT_TIME()) AS 'Current Time'
    
    FROM Test
    

    我想找出时间1和当前时间之间的差异(以分钟为单位)。我一直收到一个错误,所以我假设这可能是一个转换问题,但我无法解决它。

    小提琴: http://sqlfiddle.com/#!9/486850/47

    有人能告诉我吗谢谢

    2 回复  |  直到 6 年前
        1
  •  2
  •   Matheus Souza    6 年前
    SELECT 
    id,
    Present,
    Date,
    Time,
    TIMESTAMPDIFF(MINUTE, time, CURRENT_TIMESTAMP())
    
    FROM Test
    

    我猜你的化名让你很难受

        2
  •  0
  •   Sinto    6 年前

    您可以尝试以下查询:

    SELECT 
    id,
    Present,
    Date,
    Time,
    current_time as Current,
    TIMESTAMPDIFF(MINUTE, Time, CURRENT_TIME()) AS Time_difference
    FROM Test;
    

    Demo here