Form dates search between dates in JSON file

Hi there,

I have an Ionic app with a form. This form consists of 2 fields, type=“date”. I also have a JSON file with several requests in it, these requests do all have a start- and enddate. I would like to send these two values (dates) to my JSON file which sends back the requests between those dates (and the requests with these dates too).


<ion-view title="Search">
    <h1 class="title">Request form</h1>
    <form ng-submit="searchReportsDates()" ng-controller="searchReportsCtrl">
      <div class="list">
	      	<div class="item item-divider">
			    Search between dates
			<label class="item item-input">
			  <span class="input-label">Starts</span>
			  <input type="date" ng-model="searchData.startdate">
			<label class="item item-input">
			  <span class="input-label">Ends</span>
			  <input type="date" ng-model="searchData.enddate">
			<li class="item">
	          <button class="button button-width-red ion-checkmark"></button>


.controller('searchReportsCtrl', function($scope, $timeout, $http, $ionicLoading, RequestService) {
 	  $scope.searchData = {};
      $scope.searchReportsDates = function(){
        var data = {
        "startdate": $scope.searchData.startdate,
        "enddate": $scope.searchData.enddate
    $"http://url/to/searchreports.php", data,{"startdate": $scope.searchData.startdate, "enddate": $scope.searchData.enddate})
        .success(function(data, status, headers, config){
            $scope.requestsBetweenDates = data;
            console.log($scope.requestsBetweenDates); //this should contain the array with the requests
            // or maybe like this?
            //$scope.requestsBetweenDates = JSON.stringify(data);
        $scope.loadingIndicator = ${
		    content: 'Loading Data',
		    animation: 'fade-in',
		    showBackdrop: false,
		    maxWidth: 200,
		    showDelay: 100
        $timeout(function() {
	        $scope.searchData.startdate = "";
	        $scope.searchData.enddate = ""; 
	    }, 1000); 

PHP script


try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $data = file_get_contents('php://input');
    $vars = json_decode($data);
    $startdate = $vars->startdate;
    $enddate = $vars->enddate;
    $sql = "SELECT * FROM Requests, Users WHERE Requests.startdate=? AND Requests.enddate=?";
    $stmt = $conn->prepare($sql);
	$stmt->bindParam(1, $startdate);
	$stmt->bindParam(2, $enddate);
	$result = $stmt->fetchAll(PDO::FETCH_ASSOC); //array(0){}
	if($result) {

foreach ($result as $row){

header('Content-type: application/json');
echo '' . json_encode($return) .'';
return true;

} else {
	return false;

$conn = null;

catch(PDOException $e)
    echo $sql . "<br>" . $e->getMessage();

I’m guessing that i have to convert the strings, which I send to the PHP script, to actual dates… But the dates in the database should also be converted, right?

I think everything should work, except for the PHP script, right?

Thanks in advance,


Can anyone help me with this please?

Now I found this:

var dateFrom = "02/05/2013"; //this can be my inserted startdate
var dateTo = "02/09/2013"; //this can be my inserted enddate
var dateCheck = "02/07/2013"; //this should loop through all the requests I have and only display the ones that are between the first two dates

var d1 = dateFrom.split("/");
var d2 = dateTo.split("/");
var c = dateCheck.split("/");

var from = new Date(d1[2], d1[1]-1, d1[0]);  // -1 because months are from 0 to 11
var to   = new Date(d2[2], d2[1]-1, d2[0]);
var check = new Date(c[2], c[1]-1, c[0]);

console.log(check > from && check < to)

Can anyone help me please?

Thanks in advance,


are u resolved your problm please
because i have the same structure,i whoud to have a search by date :wink: