php PHP今天的日期形式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18416795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:31:09  来源:igfitidea点击:

PHP Today's date in form

phpdate

提问by user2081876

I've got several text boxes in a form that are the input to a SQL query. I need one of the boxes to auto populate with today's date but can't get it to work :

我在一个表单中有几个文本框,它们是 SQL 查询的输入。我需要使用今天的日期自动填充其中一个框,但无法使其正常工作:

  <td align="left"><INPUT TYPE="text" MAXLENGTH="10" SIZE="10" NAME="To_Date" id=To_Date value="'.date("m/d/y").'"/></td>

displays the following in the text box:

在文本框中显示以下内容:

'.date(

'。日期(

Help is much appreciated!

非常感谢帮助!

Cheers,

干杯,

Rene

雷内

回答by Gautam3164

Try with either one like

尝试任何一个喜欢

PHP in HTML :

HTML 中的 PHP :

<input type="text" value="<?php echo date('m/d/y');?>"/>

HTML in PHP :

PHP 中的 HTML :

<?php echo "<input type='text' value='".date('m/d/y')."'";?>

Dont mesh both PHPand HTMLand another is betterto write HTMLin lower cases.

不要网既PHPHTML,另一个是更好的来写HTML较低的情况下。

回答by Shushant

alternatively you can use.

或者你可以使用。

echo '<input type="text" value="'.date('m/d/y').'"/></td>';

回答by Maxime Lorant

You're trying to use PHP in a HTML tag. You have to open the <?phptag before writing any PHP code. So your code should be:

您正在尝试在 HTML 标记中使用 PHP。<?php在编写任何 PHP 代码之前,您必须打开标签。所以你的代码应该是:

<td align="left">
     <input type="text" maxlength="10" size="10" name="To_Date" id="To_Date" value="<?php echo date("m/d/y") ?>"/>
</td>

PS: Conventions want to use lowercase attributes in HTML, so I transform a little your input ;) (Yours was HTML5 valid, but it's just convention, deh.)

PS:约定希望在 HTML 中使用小写属性,所以我对您的输入进行了一些转换;)(您的输入是 HTML5 有效的,但这只是约定,deh。)

回答by Innocent Zondo

Try this it worked for me.

试试这个它对我有用。

 <input type="text" name="Date" readonly = "readonly"  value="<?php echo date('m/d/y');?>"/>