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

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

I need to enter this date in the hidden form field when someone comes to the site. Therefore, I would need to take the date today and convert it to this format. Thanks.

+7
php
source share
5 answers

use the built-in date () function.

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

the string parameter "m / d / Y" is the return date pattern. m for two-digit months, d for a two-digit day, and Y for a four-digit year.

+29
source share
 $Date = date('m/d/Y'); 
+9
source share

How about using date function? You just need to find the right format; 'm' per month, 'd' per day, 'Y' per year using four digits, e.g.

In your case, something like this, I think:

 date("m/d/Y") 

And if you want one more day than now, use the second optional parameter.

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

Maybe this will 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('Ym-d'); ?> // 2016-04-27 
+1
source share

All Articles