• MSSQL中的日期减价法


    代码
     1  DECLARE @dt datetime;
     2  SET @dt = GETDATE();
     3  DECLARE @table table(caption varchar(20),value datetime);
     4 
     5  INSERT INTO @table VALUES('0',@dt);
     6  INSERT INTO @table VALUES('-1',@dt-1);
     7  INSERT INTO @table VALUES('-0.1',@dt-0.1);
     8  INSERT INTO @table VALUES('-0.01',@dt-0.01);
     9  INSERT INTO @table VALUES('-0.001',@dt-0.001);
    10  INSERT INTO @table VALUES('-0.0001',@dt-0.0001);
    11  INSERT INTO @table VALUES('-0.00001',@dt-0.00001);
    12  INSERT INTO @table VALUES('-0.000001',@dt-0.000001);
    13  INSERT INTO @table VALUES('-0.0000001',@dt-0.0000001);
    14  
    15  SELECT * FROM @table
    16 

    显示结果:

    caption           value
    0         2010-05-05 18:50:03.547
    -1        2010-05-04 18:50:03.547
    -0.1       2010-05-05 16:26:03.547
    -0.01       2010-05-05 18:35:39.547
    -0.001       2010-05-05 18:48:37.147
    -0.0001       2010-05-05 18:49:54.907
    -0.00001     2010-05-05 18:50:02.683
    -0.000001     2010-05-05 18:50:03.463
    -0.0000001     2010-05-05 18:50:03.540

    那么,他到底是怎么计算的。稍微专注的人立即看出,当-1时,日期刚好减去一天,所以我们可以这么理解:

    日期-1=减去1天。

    那么接下来的,只需要转换一下就明白了。

    日期-0.1=今天日期减去0.1

    是0.1天,那么0.1天是多少呢?恍然觉悟,原来是按照分钟加减的。

    1天等于24个小时乘以60分钟

    0.1等于24个小时乘以60分钟,再乘以0.1。

    这么一对,还真是这个!

  • 相关阅读:
    concate string when group by
    Regular Expression
    Login failed for user
    SQL Performance Tools
    Web References
    ARTetris-AR版俄罗斯方块的源码解析
    ARKit_1
    链表
    线性表
    ORB-SLAM2的特征提取算法
  • 原文地址:https://www.cnblogs.com/sofire/p/1728323.html
Copyright © 2020-2023  润新知