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 : 2021-10-21
If you want to add more, eg. 6 days. you
$today = new DateTime; $today->modify('+6 day');
If you want to show the time, the format is the usual H:i:s
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') and Dates in PHP and MySQL.