Αποτελέσματα Αναζήτησης
25 Δεκ 2010 · You can use the strtotime and date functions like this: echo date('Y', strtotime('2068-06-15')); Note however that PHP can handle year upto 2038. You can test it out here. If your date is always in that format, you can also get the year like this: $parts = explode('-', '2068-06-15'); echo $parts[0];
15 Σεπ 2008 · <?php $current= new \DateTime(); $future = new \DateTime('+ 1 years'); echo $current->format('Y'); //For 4 digit ('Y') for 2 digit ('y') ?> Or you can use it with one line $year = (new DateTime)->format("Y");
PHP Date/Time Reference. Example Get your own PHP Server. Format a local date and time and return the formatted date strings: <?php. // Prints the day. echo date ("l") . "<br>"; // Prints the day, date, month, year, time, AM or PM. echo date ("l jS \of F Y h:i:s A"); ?> Try it Yourself » Definition and Usage.
To get the current year with PHP date function, it is necessary to pass in the Y format as follows: <?php //Get the current year with //PHP's date function. $year = date ("Y"); echo $year; ?> Try it Yourself » This example prints out current year’s full four-digit representation.
20 Απρ 2020 · This article introduces how to get the current year in PHP, for example, date () function, strftime () function and by using the DateTime object.
23 Ιουν 2014 · Method 1: Using only date () function to get current year. PHP’s date () function can let you know date and time related information based on the formatting string it takes in its first parameter. It can take two parameters. If you use only one parameter, It will return info about the current time.
The date () function is built into PHP and can either return the current date/time or a formatted version of it. It takes two parameters: a format string and an optional Unix timestamp. The format string “Y” is used to get a full numeric representation of a year, i.e., “2022”.