Hi,

I want to get first date of month and last date of month by passing any date of month.

For e.g.

Input :-
6/2/2016

Output:-

FirstDate : 1/2/2016
Last Date :  29/2/2016

Bhaskar Bhatt Default Asked on December 9, 2015 in Programming.
Add Comment
  • 2 Answer(s)
    <?php
    
    $query_date = '2010-02-04';
    
    // First day of the month.
    $f_day=explode('-', date('Y-m-01', strtotime($query_date)));
    // Last day of the month.
    $l_day=explode('-',date('Y-m-t', strtotime($query_date)));
    echo $f_day[2];
    echo "<br/>";
    echo $l_day[2];
    ?>
    
    pranav88raval Default Answered on December 10, 2015.
    Add Comment

    <?php

    //Input Date
    $input_date = ‘6/2/2016’;
    $converted_date = str_replace(‘/’, ‘-‘, $input_date);

    echo “Input :- <br/>”.$input_date;
    echo “<br/> “;
    echo “<br/> “;
    // Get First day of the month.
    $first_day=explode(‘-‘, date(‘Y-n-1’, strtotime($converted_date)));
    // Get Last day of the month.
    $last_day=explode(‘-‘,date(‘Y-n-t’, strtotime($converted_date)));

    //Print the output
    echo “Output :- <br/>”;
    echo ” FirstDate :  “. $first_day[2].”/”.$first_day[1].”/”.$first_day[0];
    echo “<br/> “;
    echo ” LastDate : “.$last_day[2].”/”.$last_day[1].”/”.$last_day[0];

     exit;

    ?>

    Mayursinh Zala Default Answered on January 13, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.