簡體   English   中英

該月的第一天和最后一天

[英]The first day and the last day of the month

有人可以幫助我嗎,我需要獲取以下值:

  • $startTime必須是一個月的第一天,且為00:00:00 ,否則

    無效時間

  • $_GET end_date必須始終是時間為00:00:00的一個月的第一天,否則invalid date

  • $defaultEndTime必須是當前月份的第一天,時間為00:00:00
  • $endTime必須是一個月的第一天, $endTime 00:00:00 ,否則

    無效時間

  • $startTime$endTime之間的差值必須恰好是一個月

我試過了:

    $end_date=new DateTime();
    $end_date->format('Y-m-js 00:00:00');

我嘗試使用datedif獲取不同的startTime end endTime但我不知道如何獲得一個月。

獲取每月的第一天和最后一天

    $date = '2018-01-11';
    // First day with 00:00:00
    echo date('Y-m-01 00:00:00', strtotime($date ));
    echo '<br>';
    // Last day with 00:00:00
    echo date('Y-m-t 00:00:00', strtotime($date ));

輸出:

2018-01-01 00:00:00
2018-01-31 00:00:00

=>嘗試這段代碼。

<?php

echo date("Y-m-d 00:00:00", strtotime('first day of this month'));

echo "<br/>";

echo date("Y-m-d 00:00:00", strtotime('last day of this month'));

?>

演示:-https: https://eval.in/933378

 $startDate = date('01-m-Y 00:00:00',strtotime('this month')); // First day of current month

 echo $startDate;

 $endDate =  date("t-m-Y 00:00:00", strtotime($startDate ));// Last date of current month. 
 //'t' provide last day of month means if, it is Jan then get 31 
 //and also if current month is Feb then t provide 28.It's happend same as other months.

 echo $endDate ;

Lets Today是11-01-2018。 然后輸出:

  01-01-2018 00:00:00
  31-01-2018 00:00:00

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM