简体   繁体   English

如何计算今天的日期和文档中的日期之间的天差,但在弹性搜索脚本中从中消除时间

[英]How to calculate day difference between today's date and date from doc but eliminating time from it in scripts of elastic search

I tried this solution and it works but it takes time stamp also....I want to eliminate time stamp...我试过这个解决方案,它有效,但它也需要时间戳......我想消除时间戳......

"filter": {
    "script": {
        "script": { 
            "inline":"(new Date().getTime() - doc['current_edd'].date.getMillis()) /
                            (1000 * 60 * 60 * 24)  == params.missDelby",
             "params": { "missDelby": 1 }
         }
     }
 }

Use can use some math to remove the time part with this simple calcul使用这个简单的计算可​​以使用一些数学来去除时间部分

long t1 = new Date().getTime();
t1 -= t1 % (24 * 3600 * 1000); //24 * 3600 * 1000 total milliseconds in a day

The you can update your query like this您可以像这样更新您的查询

"filter": {
    "script": {
        "script": { 
            "inline": "long t1 = new Date().getTime(); 
                       long t2 = doc['PostCodeDate'].value.getMillis(); 
                       t1 -= t1 % (24 * 3600 * 1000); 
                       t2 -= t2 % (24 * 3600 * 1000);
                       return (t1 - t2) / (24 * 3600 * 1000) == params.missDelby",
             "params": { "missDelby": 1 }
         }
     }
}

I'll update my solution as soon as I found a simpler approach.我会在找到更简单的方法后立即更新我的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据库日期和今天的日期之间的差异 - Difference Between Database Date and Today's Date 如何从DatePicker小部件计算两个日期之间的差异 - How to calculate difference between two date from DatePicker widget 计算今天的日期是否在其他两个日期之间 - 但仅限日期和月份 - Calculate if today date between 2 other dates - But only with day and month 获取给定日期的日期以排除两个日期之间的差额 - Get the day of the given date to exclude from the difference between two dates 如何使用Joda-Time API从今天起获取最近24小时或7天的记录 - How to fetch the records of last 24 hours or 7 days from today's date using Joda-Time API 我如何计算预定义日期时间和最近日期时间之间的秒数差异 - How can i calculate difference in seocnds between a predefined date time and recent date time 如何解决选择今天的日期,从日期中减去几天并将日期添加到EditText的问题 - How to fix selecting today's date, deducting a few days from the date and adding the date to an EditText 从Date.getTime()计算日期/时间 - Calculate Date/Time from Date.getTime() 如何使用Java计算数据库与当前日期之间的天数差异 - How to calculate difference in days between the one from database and current date using java 如何在Java中将日期格式的时间格式转换为今天的时间? - How to convert Time format to today's time in Date format in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM