Αποτελέσματα Αναζήτησης
15 Σεπ 2008 · With PHP heading in a more object-oriented direction, I'm surprised nobody here has referenced the built-in DateTime class: $now = new DateTime(); $year = $now->format("Y"); or one-liner with class member access on instantiation (php>=5.4): $year = (new DateTime)->format("Y");
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];
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.
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.
9 Σεπ 2024 · Method 1 (Prints function name): __FUNCTION__ is used to resolve function name or method name (function in class). Example: <?php class Test { public function bar() { var_dump(__FUNCTION__); } } function foo() { var_dump(__FUNCTION__); } // Must output
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.
6 Ιουν 2021 · If you don’t want to use the DateTime class then you can simply use the PHP’s date() function to get the year from date. <?php // Date Format: Y/m/d $paymentDate = '2021/06/05';; echo $year = date('y', strtotime($paymentDate)); // echo $year = date('Y', strtotime($paymentDate)); // Output: 21 die();