Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have date picker and want my date picker to be able get below data that is available, no matter if a user select last year date; e.g. 2019-12-04. On my jquery request I can only get this year date, anyone who can help me to achieve such logic. The logic is below if perhaps I am not making a sense.

What I have tried:

HTML
<!---DatePicker for startDate and endDate ---->
<div class="d-flex justify-content-start">
  <div class="col-xl-10.5 col-lg-10.5 col-md-10 col-sm-10.5 col-10.5">
    <div class="input-daterange input-group" id="datepicker">
      <input type="text" class="input-sm form-control" name="from" placeholder="startdate" />
      <span class="input-group-addon">To</span>
      <input type="text" class="input-sm form-control" placeholder="enddate" />
    </div>
  </div>
</div><br/>
<br/>
<br/>
JavaScript
// date functionality
$(document).ready(function() {
  $('.input-daterange').datepicker({
    dateFormat: "dd-mm-yy",
    autoclose: true
  });
});

//checking equality for channel fields on thingspeak.
$(function() {
  $("#download").click(function(e) {
    e.preventDefault();
    var isTemperature = $('#temperature').is(':checked');
    var isButtonState = $('#button_state').is(':checked');

    if (isTemperature && isButtonState) {
      window.open('https://api.thingspeak.com/channels/952961/feeds.csv?api_key=FDJCRN71YJM2R0FM&start=2020-01-06T00:00+02&end=2020-01-10T23:59+02:00&timezone=Africa/Johannesburg');
    } else {
      if (isTemperature) {
        window.open('https://api.thingspeak.com/channels/952961/fields/1.csv?api_key=FDJCRN71YJM2R0FM&timezone=Africa/Johannesburg');
      } else {
        if (isButtonState) {
          window.open('https://api.thingspeak.com/channels/952961/fields/8.csv?api_key=FDJCRN71YJM2R0FM&start=2020-01-06T00:00+02&end=2020-01-10T23:59+02:00&timezone=Africa/Johannesburg');
        }
      }
    }

  });
});
Posted
Updated 8-Jan-20 4:23am
v2

1 solution

hello if i undestand your question, you want to select only current year dates , right ?
in jquery datetimepicker you can set minDate and maxDate ,

i.e

$(document).ready(function() {

var year = (new Date).getFullYear();

  $('.input-daterange').datepicker({
    dateFormat: "dd-mm-yy",
    autoclose: true,
    minDate: new Date(year, 0, 1),
    maxDate: new Date(year, 11, 31)

  });
});


year variable is dynamic , it takes the current year .
 
Share this answer
 
Comments
gcogco10 8-Jan-20 9:33am    
Ok how do I then, reference my jquery request for passing data using JqueryUI date-picker?
tninis 8-Jan-20 9:38am    
get the selected dates inputs values and use them . i.e for single date

retrieve the value:
var selectedDate=$('#date-input').val() ;

and put it in the API URL :

window.open('https://api.thingspeak.com/channels/952961/fields/8.csv?api_key=FDJCRN71YJM2R0FM&start='+selectedDate+'&end=2020-01-10T23:59+02:00&timezone=Africa/Johannesburg');

**change the date format based on your needs.

gcogco10 9-Jan-20 1:20am    
Thanks mates, i took the last responce and its working well as i have tested.
gcogco10 9-Jan-20 2:17am    
Last question is end date on my API URL, which means i have to manually change its time. Is there way around this? Please advice, thanks.
tninis 9-Jan-20 3:10am    
what you mean "manually" ? show me an example

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900