簡體   English   中英

如何獲取當月的當前日期和最后一天

[英]How to get the current day and last day of the current month

我只是一個初學者! 我需要一個html數字輸入,以每月的今天為最小值,以當月的一天為最大值。

在PHP中,我聲明$today = date ('Ymd,time()); 讀取今天的日期,我不知道如何在<Input type="number" min="" max="" />中以最小數字形式聲明月份的值?

如果我正確閱讀了您的問題,則需要一個表示每月某天的html輸入。 而您想要的最小值是今天。

如果是這樣的話:

您可以格式化日期並將其用作值。

$today = new DateTime();
// Day of the month, 2 digits with leading zeros
$day_today; = $today->format('d');
// OR
//  Day of the month without leading zeros
$day_today; = $today->format('J');

//  Last day of the given month in datetime 
$last_day; = $today->format('t');

Choose day:<input type="number" min="<?php echo $day_today; ?>" max="<?php echo $last_day; ?>" />
<Input type="number" min="<?= date('d') ?>" max="<?= date('t') ?>" />

我認為這可以幫助您...

暫無
暫無

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

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