YouTip LogoYouTip

Func Date Date Format

```html PHP date_format() Function | Rookie Tutorial /* Basic styling to mimic original layout - not required but helpful for readability */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; } .header { background: #f5f5f5; padding: 10px; } .navbar { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px; } .navbar li { display: inline; } .sidebar { width: 200px; float: left; background: #eee; padding: 10px; } .sidebar ul { list-style: none; padding: 0; } .content { margin-left: 220px; padding: 20px; } pre { background: #f4f4f4; padding: 10px; border: 1px solid #ddd; overflow-x: auto; } code { background: #f4f4f4; padding: 2px 4px; }

PHP date_format() Function

This tutorial is from Rookie Tutorial.

Definition and Usage

The date_format() function returns a date formatted according to the specified format.

Note: This function does not use the locale setting (uselocale). Use strftime() to format dates according to locale.

Syntax

date_format(object, format)

Parameter Values

Parameter Description
object Required. Specifies a DateTime object returned by date_create()
format Required. Specifies the format for the date. Uses the same format as the date() function.

Technical Details

  • Return Value: Returns the formatted date string on success, or FALSE on failure.
  • PHP Version: 5.2+

Example 1

Format a date:

<?php
$date=date_create("2013-03-15");
echo date_format($date,"Y/m/d");
?>

Example 2

Format a date using a different format:

<?php
$date=date_create("2013-03-15");
echo date_format($date,"Y-m-d H:i:s");
?>

Example 3

Format a date using a custom pattern:

<?php
$date=date_create("2013-03-15");
echo date_format($date,"l jS \of F Y");
?>

Complete PHP Date Reference

For a complete reference of all PHP date functions, visit our PHP Date Reference.

Note: This page is a translation of the original Chinese tutorial from Rookie Tutorial.

```
← Func Date Get Last ErrorsFunc Date Date Diff β†’