Support

Account

Home Forums General Issues Query between dates using Date Picker fields Reply To: Query between dates using Date Picker fields

  • No manual month changes. I can handle that easily with some date variable manipulation.

    On my site i have a widget that uses AJAX to send the month and year to the page. I grab those values and make some date variables.

    Mainly i look at today and get the month and year. I make a variable for the first of the month like this: 20140601 — i store that value in a variable. Then i also get the last day of the given month and make my ending day variable with that value. I use php “t” value to get the last day of the month.

    That code ends up looking like this:

    $current_month = str_pad($_GET['_m'], 2, '0', STR_PAD_LEFT);
    $current_day = "01"; // day one
    $current_year = $_GET['_y'];
    	
    $get_last_day = $current_year.$current_month.$current_day;
    $lastday = date("t", strtotime($get_last_day));
    	
    $tempstartday = $current_year.$current_month.$current_day;
    $tempendday = $current_year.$current_month.$lastday;
    	
    $startday = date('Ymd', strtotime($tempstartday));
    $endday = date('Ymd', strtotime($tempendday));

    In my final code, i pass the $startday and $endday to the wordpress query in each of those spots where in the example I have the date hardcoded.

    'value' => $startday,