我们如何在 Jquery 日历中获取所选月份的开始和结束日期

How we can get start and end date of selected month in Jquery Calender

Jquery代码

<link rel="stylesheet" href="assets/calender/jquery-ui.css">
<script src="assets/calender/jquery-ui.js"></script>

HTML代码

      <form autocomplete="off" id="sendform" method="post" action="#" >
         <div class="row" style="margin-top:7px;">    
            <div class="col-sm-2">
               <div class="form-group">
               <label  > Start date of Month <font style="color:#ff0000;font-size:16px"> *</font> </label>      
                  <input type="text"  name="sdtgmt"    id="sdtgmt" required   class="form-control"  >
               </div>
            </div>
         </div>
            <div class="row" style="margin-top:7px;">     
            <div class="col-sm-2">
               <div class="form-group">
                <label  > End date of Month <font style="color:#ff0000;font-size:16px"> *</font> </label>       
                  <input type="text"  name="edtgmt"  id="edtgmt" required   class="form-control"  >
               </div>
            </div>
         </div>        
         <div class="row" style="margin-top:7px;">
         <div class="col-sm-12">
            <div class="form-group"><button type="submit" name="submit_row" value="Submit" class="btn btn-primary" ><i class="fa fa-align-justify"></i>&nbsp;&nbsp;  SUBMIT</button></label>                     
      </form>

PHP代码

if (isset($_POST['submit_row']))
{
    $sdtgmt_x = $_POST['sdtgmt'];
    $edtgmt_x = $_POST['sdtgmt'];

    $sdtgmt = date("Y-m-d", strtotime($_POST['sdtgmt']));
    $edtgmt = date("Y-m-d", strtotime($_POST['sdtgmt']));

    echo "$sdtgmt";
    echo "<br>";
    echo "$edtgmt";
    exit;
}   

It is showing only mm-yyy but I want in post value as full date of start and end. For example if we have selected "Sep 2019" then it should show as sdtgmt - 2019-09-01 and edtgmt - 2019-09-30

您可以在php

中使用date方法

例如:

<?php

$dt = "2019-09";
echo 'First day : '. date("Y-m-01", strtotime($dt)).' - Last day : '. date("Y-m-t", strtotime($dt));

解释代码:

Y:年份

米:一个月

01: 静态数字是指一个月中的第一天

t:给定月份的天数

您可以从 php.net 网站上了解此方法

t 给出给定月份的天数。参见 https://www.php.net/manual/en/function.date.php

  <?php
  $sdtgmt = date("Y-m-d", strtotime($_POST['sdtgmt']));
  $edtgmt = date("Y-m-t", strtotime($_POST['sdtgmt']));
  echo "$sdtgmt <br>";
  echo "$edtgmt <br>";
  ?>