tags:

views:

139

answers:

3

How do I create a variable in PHP of today's date of MM/DD/YYYY format?

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.

+3  A: 

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

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.

Pascal MARTIN
+1  A: 
$Date = date('m/d/Y');
Adinochestva
don't forget the ' or " and tack the ; on as well: $date = date('m/d/y');
Kris
+6  A: 

use the builtin date() function.

$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.

farzad