Date query with the current date between two date_time columns

夙愿已清 提交于 2019-12-11 03:53:31

问题


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:


  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.



来源:https://stackoverflow.com/questions/26070855/date-query-with-the-current-date-between-two-date-time-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!