# PHP DateTime formatting cribsheet

Usage with php datetime object or [Carbon](https://carbon.nesbot.com/)

{% tabs %}
{% tab title="Time" %}

### Hour

| Character | Description                                     | Example           |
| :-------: | ----------------------------------------------- | ----------------- |
|     H     | 24-hour format of an hour with leading zeros    | *00* through *23* |
|     G     | 24-hour format of an hour without leading zeros | *0* through *23*  |
|     h     | 12-hour format of an hour with leading zeros    | *01* through 12   |
|     g     | 12-hour format of an hour without leading zeros | *1* through *12*  |
|     a     | Lowercase Ante meridiem and Post meridiem       | `am` or `pm`      |
|     A     | Uppercase Ante meridiem and Post meridiem       | `AM` or `PM`      |

### Minutes and Seconds

|   Character  | Description                | Example           |
| :----------: | -------------------------- | ----------------- |
|       i      | Minutes with leading zeros | *00* through *59* |
|       s      | Seconds with leading zeros | *00* through *59* |
|       u      | Microseconds               | eg *123456*       |
|       v      | Milliseconds               | eg *654*          |
| {% endtab %} |                            |                   |

{% tab title="Date" %}

### Day

| Character | Description                                                    | Example                                                    |
| :-------: | -------------------------------------------------------------- | ---------------------------------------------------------- |
|     d     | Day of the month, 2 digits with leading zeros                  | *01* through *31*                                          |
|     j     | Day of the month without leading zeros                         | *1* through *31*                                           |
|     D     | Textual representation of a day, three letters                 | *Mon* through *Sun*\*\*                                    |
|     l     | (lowercase L) Full textual representation of a day of the week | <p><em>Monday</em> through </p><p><em>Sunday</em> \*\*</p> |
|     N     | ISO-8601 numeric representation of the day of the week         | <p><em>1</em> through <em>7</em> </p><p>(mon=1)</p>        |
|     S     | English ordinal suffix for the day of the month                | *st*, *nd*, *rd*, or *th*                                  |
|     w     | Numeric representation of the weekday                          | *0* (sun) through *6*                                      |
|     z     | The day of the year (zero index for Jan 1)                     | *0* through *365*                                          |

### Week

| Character | Description                                            | Example                                                        |
| :-------: | ------------------------------------------------------ | -------------------------------------------------------------- |
|     W     | ISO-8601 week number of year, weeks starting on Monday | <p>Example: <em>42</em> </p><p>(the 42nd week in the year)</p> |

### Month

| Character | Description                                                        | Example                      |
| --------- | ------------------------------------------------------------------ | ---------------------------- |
| m         | Numeric representation of a month, with leading zeros              | *01* through *12*            |
| n         | Numeric representation of a month, without leading zeros           | *1* through *12*             |
| M         | A short textual representation of a month, three letters           | *Jan* through *Dec \*\**     |
| F         | A full textual representation of a month, such as January or March | *January* through *December* |
| t         | The number of days in the given month                              | *28* through *31*            |

### Year

| Character | Description                                                                                                                                                         | Example                                    |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| Y         | a four digit numeric representation of the year                                                                                                                     | *2020* or *1999*                           |
| y         | a two digit numeric representation of the year                                                                                                                      | *20* or *99*                               |
| L         | Whether it is a leap year                                                                                                                                           | <p>1 for leap year, </p><p>0 otherwise</p> |
| o         | ISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. | 2020 or 1999                               |

\*\* can be varied through localisation
{% endtab %}

{% tab title="Other" %}

|   Character   | Description                                                             | Example                           |
| :-----------: | ----------------------------------------------------------------------- | --------------------------------- |
|       c       | ISO 8601 Full Date Time                                                 | `2020-06-26T13:40:10+00:00`       |
|       r       | [ RFC 2822](http://www.faqs.org/rfcs/rfc2822) formatted date            | `Fri, 26 Jun 2020 13:41:32 +0100` |
|       U       | Seconds since the Unix Epoch (commonly referred to as timestamp format) | *1593175400*                      |
|  {% endtab %} |                                                                         |                                   |
| {% endtabs %} |                                                                         |                                   |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://talltips.novate.co.uk/laravel/php-datetime-formatting-cribsheet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
