Satchel
Satchel

Reputation: 16734

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

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.

Upvotes: 9

Views: 84713

Answers (6)

MAKSTYLE119
MAKSTYLE119

Reputation: 48

<?php
echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
echo "Today is " . date("Y-m-d") . "<br>";

?>

Upvotes: 0

Kalpesh Desai
Kalpesh Desai

Reputation: 1421

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 

Upvotes: 6

Imran Khan
Imran Khan

Reputation: 31

<?php
$currentdate = date('m/d/Y');
echo "The Current Date is: $currentdate";
?>

Upvotes: 1

Sadegh
Sadegh

Reputation: 6854

$Date = date('m/d/Y');

Upvotes: 11

Pascal MARTIN
Pascal MARTIN

Reputation: 401182

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.

Upvotes: 7

farzad
farzad

Reputation: 8855

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.

Upvotes: 38

Related Questions