➤ The PHP date() function is used to format a date and/or a time. ➤ First of all, to get the right information, we need to set the default timezone:
date_default_timezone_set('Asia/Tbilisi');
• d - Represents the day of the month (01 to 31)
echo date("d"); // outputs:  current day of the month (01 to 31)
• D - A textual representation of a day (three letters)
echo date("D"); // outputs:  currnet day (three letters)
• m - Represents a month (01 to 12)
echo date("m"); // outputs:  current month (01 to 12)
• Y - Represents a year (in four digits)
echo date("Y"); // outputs:  current year (in four digits)
• l - Represents the day of the week
echo date("l"); // outputs:  current day (A full textual)
*
echo "Today is " . date("Y/m/d");  // outputs: Today is 2022/10/17
echo "Today is " . date("Y.m.d");  // outputs: Today is 2022.10.17
echo "Today is " . date("Y-m-d");  // outputs: Today is 2022-10-17
echo "Today is " . date("l");  // outputs: Today is Monday
• H - 24-hour format of an hour (00 to 23)
echo date("H"); // outputs:  current hour (00 to 23)
• h - 12-hour format of an hour with leading zeros (01 to 12)
echo date("h"); // outputs:  currnet hour (01 to 12)
• i - Minutes with leading zeros (00 to 59)
echo date("i"); // outputs:  current minutes (00 to 59)
• s - Seconds with leading zeros (00 to 59)
echo date("s"); // outputs:  current seconds (00 four 59)
• a - Lowercase Ante meridiem and Post meridiem (am or pm)
echo date("a"); // outputs:  current am/pm
by Levani Makhareishvili
2 years ago
PHP
Function
1
Pro tip: use ```triple backticks around text``` to write in code fences