Welcome Guest, Not a member yet? Register   Sign In
getting the last day of the month
#1

(This post was last modified: 08-28-2020, 10:41 AM by jreklund.)

I am using DatePicker to have a user set the date.

Code:
<form method="post">
    <?php
    DateTimePicker::create(array(
        "name" => "datePicker",
        "maxDate" => "@endDatePicker",
        "format" => "YYYYMM",
        "themeBase" => "bs4",
    ));
    ?>
    <button type="submit">Submit</button>
</form>

the user can enter for example 201906 which to me means the last day of June, 2016. But when I get the value from

Code:
if (!empty($_POST["datePicker"])) {
    $timestamp= strtotime($_POST["datePicker"]);
    echo gmdate("Y-m-d", $timestamp);

The date I get is 20190601 (in YYYYMMDD). I really need it to be 20190630. The reason is that I need to get a period of 365 days. I see that there is some way to use srtotime to specify one year before, but it would help if the unix style date was the end of the month, not the start of the month.
proof that an old dog can learn new tricks
Reply
#2

Hi. Use:

PHP Code:
echo gmdate("Y-m-t"$timestamp); 

Use "t" to get the number of days in a month.

https://www.php.net/manual/en/datetime.format.php
Reply




Theme © iAndrew 2016 - Forum software by © MyBB