Answers for "php display year"

PHP
8

php get current year

// get current year using php
<?php echo date("Y"); ?>
Posted by: Guest on August-03-2020
14

php get current year

$currentYear=date("Y");//2019
Posted by: Guest on October-30-2019
3

get current year php

// current year
<?php echo date("Y"); ?>
// current month
<?php echo date("m"); ?>
// current day
<?php echo date("d"); ?>
Posted by: Guest on November-17-2020
6

php format date

<?php
  // To change the format of an existing date
  $old_date_format = "20/03/1999";
  $new_data_format = date("Y-m-d H:i:s", strtotime($old_date_format));
Posted by: Guest on April-14-2020
3

php week of a date

Things to be aware of when using week numbers with years.

<?php
echo date("YW", strtotime("2011-01-07")); // gives 201101
echo date("YW", strtotime("2011-12-31")); // gives 201152
echo date("YW", strtotime("2011-01-01")); // gives 201152 too
?>

BUT

<?php
echo date("oW", strtotime("2011-01-07")); // gives 201101
echo date("oW", strtotime("2011-12-31")); // gives 201152
echo date("oW", strtotime("2011-01-01")); // gives 201052 (Year is different than previous example)
?>

Reason:
Y is year from the date
o is ISO-8601 year number
W is ISO-8601 week number of year

Conclusion:
if using 'W' for the week number use 'o' for the year.
Posted by: Guest on March-28-2020

Browse Popular Code Answers by Language