How do I create a variable in PHP of today's date of MM/DD/YYYY format?
如何在今天的MM / DD / YYYY格式日期以PHP創建變量?
I need to input that date as a hidden form field when someone comes onto the site. So I would need to grab today's date and convert it into that format. Thanks.
當有人進入網站時,我需要將該日期輸入為隱藏的表單字段。所以我需要抓住今天的日期並將其轉換為該格式。謝謝。
5 个解决方案
#1
31
use the builtin date() function.
使用builtin date()函數。
$myDate = date('m/d/Y');
the string parameter 'm/d/Y' is the returned date pattern. m is for 2 digit months, d for 2 digit day value and Y for 4 digit year value.
字符串參數'm / d / Y'是返回的日期模式。 m表示2個數字月份,d表示2位數日值,Y表示4位數年份值。
#2
10
$Date = date('m/d/Y');
#3
6
What about using the function date ? Just have to find the right format ; 'm' for month, 'd' for day, 'Y' for year using four digits, for instance
使用功能日期怎么樣?只需找到正確的格式; '是'月份,'d'代表白天,'Y'代表年份,例如四位數
In your case, something like this, I guess :
在你的情況下,我猜這樣的事情:
date("m/d/Y")
And if you want another day than now, use the second optional parameter.
如果你想要比現在更多的一天,請使用第二個可選參數。
#4
1
$currentdate = date('m/d/Y');
echo "The Current Date is: $currentdate";
?>
#5
1
May be this one help you :)
可能這一個幫你:)
<?php echo $todaydate = date('m/d/Y'); ?> // 04/27/2016
<?php echo $todaydate = date('m/d/y'); ?> // 04/27/16
<?php echo $todaydate = date('Y'); ?> // 2016
<?php echo $todaydate = date('Y-m-d'); ?> // 2016-04-27