How to get previous year using PHP

前端 未结 9 749
生来不讨喜
生来不讨喜 2021-02-01 01:30

How am I able to get the value of the previous year using PHP. Are there any predefined functions for it?

相关标签:
9条回答
  • 2021-02-01 01:34

    If you want to display the entire date exactly 1 year ago, including the month and year:

     <?php echo date("M d Y", strtotime("-1 year")); ?>
    
    0 讨论(0)
  • 2021-02-01 01:36

    This thread needs an update.

    Nowadays you would use the PHP date-time object and do something like this:

    $lastYear = new DateTime();
    $lastYear->sub(new DateInterval('P1Y'));
    echo $lastYear->format('Y');
    
    0 讨论(0)
  • 2021-02-01 01:36

    you can give a value of the input tag as :

    <?php echo date("Y-m-d",strtotime("-1 year"));?>
    
    0 讨论(0)
  • 2021-02-01 01:38

    try

    echo date("Y",strtotime("-1 year"));
    
    0 讨论(0)
  • 2021-02-01 01:38

    Try This

    date('Y', strtotime('last year'));
    
    0 讨论(0)
  • 2021-02-01 01:43
    $year = date("Y");
    $previousyear = $year -1;
    

    http://php.net/manual/de/function.date.php

    0 讨论(0)
提交回复
热议问题