DateTime class and weeknumber using the date() function

Posted under » PHP on 21 October 2013

DateTime in PHP class is available in PHP 5 and higher versions. This creates a date object which we can use in our script.

$today = new DateTime;
echo $today->format('Y-m-d');

Will give : 2013-10-21

If you want to show the time, the format is the usual H:i:s

For more info.

Getting the week number for a date in PHP is simple. Just use the powerful date() function that takes a format string and an optional unix timestamp as arguments. If you omit the second argument, it returns the current date/time in the given format.

Get the current week number and print it.

$currentWeekNumber = date('W');
echo 'Week number:' . $currentWeekNumber;

See also MKTIME and date('Y-m-d').

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS