日期查询与当前日期在两个date_time列之间 [英] Date query with the current date between two date_time columns

查看:172
本文介绍了日期查询与当前日期在两个date_time列之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有两个date_time列的融合表。第一个是开始日期(Startdatum),另一列是结束日期(Einddatum)。



我想用当前日期进行查询,仅在当前日期位于开始和结束日期之间的地图上显示KML行。



我尝试使用以下代码创建一个日期的字符串格式:

  var time_date = new Date(); 
var day = time_date.getDate();
var month = time_date.getMonth()+ 1;
var year = time_date.getFullYear();
var date =(year +。+ month +。+ day);

要在地图上显示KML行,我尝试使用以下代码:

  layer = new google.maps.FusionTablesLayer({
map:map,
heatmap:{enabled:false}
查询:{
select:col2,
from:1mOMP1seJq4FdiNTugsfylZaJc8sKcSlfJKUuTJjv,
其中:'Startdatum'< = date AND'Einddatum'> = date

},
选项:{
styleId:2,
templateId:2
}
});

不幸的是,地图显示了所有KMS行,而不管其中一列是什么日期。 p>

我做错了什么?

解决方案


  1. 其中 -clause是错误的,它必须是

     其中:Startdatum< ='+ date +'和Einddatum> ='+ date +'


  2. date -format似乎是错误的。虽然在文档中定义了使用的格式 yyyy.MM.dd ,但它不起作用。格式 yyyy-MM-dd 目前适用于我(但在文档中没有定义)。

      var date =(year + - + month + - + day); 

    (如果日期和月份小于10,则不符合模式,但是似乎不是一个问题)


除此之外:当您修复这两个提到的部分时,它目前工作(对我而言),但是我已经在几个小时前试过了,结果不稳定。


I have a fusion table with two date_time columns. The fist one is the start date (Startdatum) and in the other column is the end date (Einddatum).

I want to do a query with the current date, and only show the KML-lines on a map where the current date lies between the start and end date.

I tried to use the code below to create a string with a date format:

var time_date = new Date();
var day = time_date.getDate(); 
var month = time_date.getMonth()+1;
var year = time_date.getFullYear();
var date = (year+"."+month+"."+day);

To show the KML-lines on the map I tried to use the following code:

 layer = new google.maps.FusionTablesLayer({
  map: map,
  heatmap: { enabled: false },
  query: {
    select: "col2",
    from: "1mOMP1seJq4FdiNTugsfylZaJc8sKcSlfJKUuTJjv",
    where: "'Startdatum' <= date AND 'Einddatum' >= date"

  },
  options: {
    styleId: 2,
    templateId: 2
  }
});

Unfortunatly the map shows all the KMS-lines regardless what date is in one of the columns.

What am I doing wrong?

解决方案

  1. the where-clause is wrong, it has to be

    where: "Startdatum <= '"+date+"' AND Einddatum >= '"+date+"'"
    

  2. the date-format seems to be wrong. Although the used format yyyy.MM.dd is defined in the documentation, it doesn't work. The format yyyy-MM-dd currently works for me(but it's not defined in the documentation).

    var date = (year+"-"+month+"-"+day); 
    

    (in case that day and month be less than 10 they wouldn't match the pattern, but that doesn't seem to be an issue)

Beyond that: when you fix these 2 mentioned parts it currently works(for me), but I've tried it a couple of hours ago and got unstable results.

这篇关于日期查询与当前日期在两个date_time列之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆