微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

数据库从两列中取最低的日期值并计算天数

如何解决数据库从两列中取最低的日期值并计算天数

我有两列记录日期和时间,列“DataDaInstauracao”和“DataDaDenuncia”。从这两列中,我需要获取“DataDaInstauracao”和“DataDaDenuncia”中最短时间的日期,然后将天数显示在屏幕上。

表格:

enter image description here

我已经有一个公开的数据列表,我用它来获取已经组装的该表的列:

// --------- graficos com base na TR_CRIME_AUTOR ---------
        public List<CrimeAutorModel> GetAllCrimeAutorModel()
        {
            using (IDbConnection cn = ConnectionAnaliseCriminal)
            {
                try
                {
                    cn.open();
                    string query = "SELECT COD_CRIME_AUTOR"
                                   + ",DataDaDenuncia"                                  
                                   + " FROM dbo.TR_CRIME_AUTOR"
                                   + " WHERE DT_EXCLUSAO_LOGICA IS NULL";

                    return cn.Query<CrimeAutorModel>(query).ToList();
                }
                finally
                {
                    cn.Close();
                }
            }
        }

   public List<InqueritoModel> GetAllInqueritoModel()
    {
        using (IDbConnection cn = ConnectionAnaliseCriminal)
        {
            try
            {
                cn.open();
                string query = "SELECT COD_INQUERITO"
                               + ",DataDaInstauracao"                                  
                               + " FROM dbo.TP_INQUERITO"
                               + " WHERE DT_EXCLUSAO_LOGICA IS NULL";

                return cn.Query<InqueritoModel>(query).ToList();
            }
            finally
            {
                cn.Close();
            }
        }
    }

而且我还在控制器上安装了 Ajax,它接收数据并使用它来传递 JS:

// --------- graficos com base na TR_CRIME_AUTOR ----------
        [HttpGet] public JsonResult AjaxGetAllCrimeAutorModel() => Json(new DashboardDados().GetAllCrimeAutorModel());

// --------- graficos com base na TP_INQUERITO ----------
        [HttpGet] public JsonResult AjaxGetAllInqueritoModel() => Json(new DashboardDados().GetAllInqueritoModel());

而且我有函数的基础:

async function shortestTimeDays() {

    let resultado,numberOfDays = 0;

    //chama o método ajax que trás todos os objetos
    try {
        const resposta = await fetch(`/Dashboard/AjaxGetAllCrimeAutorModel`);
        resultado = await resposta.json();
    } catch (e) {
        console.error("Erro ao realizar fetch");
        return console.error(e);
    }
  
    try {
          const resposta = await fetch(`/Dashboard/AjaxGetAllInqueritoModel`);
          resultado = await resposta.json();
      } catch (e) {
          console.error("Erro ao realizar fetch");
          return console.error(e);
      }
  
}

现在我想知道我应该如何使用 javascript 来实现我的目标并能够在屏幕上播放结果。

enter image description here

<div class="blocoprocessos" style="margin-bottom: 2em;">
  <div style="width: 100%;text-align:center;">
    <div>
      <span style="font-size: 20px;font-weight: 400;">Tempo minimo fase pré-processual</span>
    </div>
    <hr class="hrBlocoprocesso" style="margin-bottom: 5px;margin-top: 10px;" />
    <div style="display: flex;flex-direction: column;align-items: center;">
      <span>Tempo (em dias)</span>
      <span style="font-size: 25px;">*</span>
    </div>
  </div>
</div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?