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

后端 未结 6 1265
天涯浪人
天涯浪人 2021-01-02 10:56

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 wo

相关标签:
6条回答
  • 2021-01-02 11:04
    <?php
    $currentdate = date('m/d/Y');
    echo "The Current Date is: $currentdate";
    ?>
    
    0 讨论(0)
  • 2021-01-02 11:04
    <?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>";
    
    ?>
    
    0 讨论(0)
  • 2021-01-02 11:08

    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.

    0 讨论(0)
  • 2021-01-02 11:15
    $Date = date('m/d/Y');
    
    0 讨论(0)
  • 2021-01-02 11:23

    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.

    0 讨论(0)
  • 2021-01-02 11:27

    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 
    
    0 讨论(0)
提交回复
热议问题