0

Jquery Code

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

HTML Code

      <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 Code

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

Rakesh
  • 19
  • 6

2 Answers2

1

You can use date method in php

for example:

<?php

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

Explain code:

Y: for year

m: for month

01: static number refer to first day in month

t: Number of days in the given month

You can read about this method from php.net website

Anees Hikmat Abu Hmiad
  • 3,460
  • 2
  • 19
  • 36
1

t Gives you the number of days in the given month. See 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>";
  ?>