{"id":12462,"date":"2016-05-18T16:15:38","date_gmt":"2016-05-18T13:15:38","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=12462"},"modified":"2018-01-09T10:58:30","modified_gmt":"2018-01-09T08:58:30","slug":"php-date-format-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/","title":{"rendered":"PHP Date Format Example"},"content":{"rendered":"<p>In this example, we shall show how to deal with dates in PHP. As dates can be represented in many different ways. It is important to find a way that helps to avoid possible unexpected errors that may arise.<\/p>\n<p>For this example, we will use:<\/p>\n<ul>\n<li>Ubuntu (14.04) as Operating System.<\/li>\n<li>Apache HTTP server (2.4.7).<\/li>\n<li>PHP (5.5.9).<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;8njY7i2QRy6sg8pg&#8217;]<\/p>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip environment preparation creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<h2>1. Preparing the environment<\/h2>\n<h3>1.1. Installation<\/h3>\n<p>Below, commands to install Apache and PHP are shown:<\/p>\n<pre class=\"brush:bash\">sudo apt-get update\r\nsudo apt-get install apache2 php5 libapache2-mod-php5\r\nsudo service apache2 restart<\/pre>\n<p><strong>Note:<\/strong> if you want to use Windows, installing XAMPP is the fastest and easiest way to install a complete web server that meets the prerequisites.<\/p>\n<h2><span id=\"code\">2. How should dates be stored?<\/span><\/h2>\n<p>As you will probably know, the date representation varies from region to region. For example, in UK, we would say that today is 13\/05\/2016; whereas in US, we would represent it as 05\/13\/2016.<\/p>\n<p>This can lead to a problem. If we have a system that needs to do some calculations basing on the date, if a date is in an unexpected format, we would have nonsense results.<\/p>\n<p>To solve this, a system known as <strong>Unix time<\/strong>, also known as <strong>Epoch time<\/strong> was proposed. What this system does, is describe time instants: it&#8217;s defined as the number of seconds passed from 01\/01\/1970 at 00:00:00 (UTC). So, the date we mentioned above, in Unix time, would be <code>1463097600<\/code> (truncated to the day start, at 00:00:00).<\/p>\n<p>We could define it as a &#8220;cross-region\/language time representation&#8221;.<\/p>\n<p>The Unix time is universally used not only in Unix-like systems, but also in many other computational systems. So, with Unix time, we have widely used standard that does not depend on any region or system configuration. In the case a user has to deal with this data, the only thing we would have to do is to transform it to a human-readable format.<\/p>\n<p><strong>Note:<\/strong> Unix time is not a real representation of UTC, as it does not represent leap seconds that UTC does.<\/p>\n<h2>3. PHP examples<\/h2>\n<h3>3.1. From time stamp to human-readable<\/h3>\n<p>Below, we are seeing how to get the current time stamp, and to get a formatted date:<\/p>\n<p><em><span style=\"text-decoration: underline;\">timestamp_to_human.php<\/span><\/em><\/p>\n<pre class=\"brush:php\">&lt;?php\r\n\r\n$timestamp = time();\r\n$date = date('d-m-Y', $timestamp);\r\n$datetime = date('d-m-Y h:i:s', $timestamp);\r\n\r\necho \"Unix timestamp: $timestamp &lt;br&gt;\";\r\necho \"Human-readable date: $date &lt;br&gt;\";\r\necho \"Human-readable datetime: $datetime\";<\/pre>\n<p>The <code>date()<\/code> function supports a wide list of formats, some of them are:<\/p>\n<ul>\n<li><code>l<\/code> for day name.<\/li>\n<li><code>N<\/code> for day number of the week, being Monday the first.<\/li>\n<li><code>z<\/code> for day number of year.<\/li>\n<li><code>W<\/code> for month number of year.<\/li>\n<\/ul>\n<p>Updating the script to use them:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>timestamp_to_human.php<\/em><\/span><\/p>\n<pre class=\"brush:php\">echo 'Day name: ' . date('l', $timestamp) . '&lt;br&gt;';\r\necho 'Day number of week: ' . date('N', $timestamp) . '&lt;br&gt;';\r\necho 'Day number of year: ' . date('z', $timestamp) . '&lt;br&gt;';\r\necho 'Month number of year: ' . date('W', $timestamp) . '&lt;br&gt;';<\/pre>\n<p><strong>Note: <\/strong>the second parameter, were we have specified the time stamp, is optional. If we don&#8217;t specify any time stamp, current will be used.<\/p>\n<h3>3.2. From human-readable to time stamp<\/h3>\n<p>Now, the reverse process: from human-readable format, to Unix time stamp:<\/p>\n<p><em><span style=\"text-decoration: underline;\">human_to_timestamp.php<\/span><\/em><\/p>\n<pre class=\"brush:php\">&lt;?php\r\n\r\n$ukDate = '13-05-2016'; \/\/ For UK format, '-' must be the separator.\r\n$usDate = '05\/13\/2016'; \/\/ For US format, '\/' must be the separator.\r\n\r\n$ukTimestamp = strtotime($ukDate);\r\n$usTimestamp = strtotime($usDate);\r\n\r\necho \"Timestamp created from UK date format: $ukTimestamp &lt;br&gt;\";\r\necho \"Timestamp created from US date format: $usTimestamp\";<\/pre>\n<p><code>strtotime()<\/code> function does the job. Additionally, the function supports expressions like:<\/p>\n<ul>\n<li>Adverbs, like <code>now<\/code>, <code>tomorrow<\/code>; and <code>next Friday<\/code>, <code>last Saturday<\/code>, etc.<\/li>\n<li>Mathematical expressions, e.g., <code>+2 weeks 5 days 12 hours<\/code>.<\/li>\n<\/ul>\n<p>Let&#8217;s see it:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>human_to_timestamp.php<\/em><\/span><\/p>\n<pre class=\"brush:php\">echo \"Tomorrow's time stamp is: \" . strtotime('tomorrow') . '&lt;br&gt;';\r\necho 'And in 2 weeks, 5 days and 12 hours time: ' . strtotime('+2 weeks 5 days 12 hours') . '&lt;br&gt;';<\/pre>\n<h3>3.3. DateTime class<\/h3>\n<p>Apart from those functions, it is also available a class named <code>DateTime<\/code>, with some useful methods.<\/p>\n<p>We can, for example, calculate the difference between two dates:<\/p>\n<p><em><span style=\"text-decoration: underline;\">difference_with_datetime.php<\/span><\/em><\/p>\n<pre class=\"brush:php\">&lt;?php\r\n\r\n$currentDate = new DateTime();\r\n$targetDate = new DateTime('19-01-2038'); \/\/ Date when Unix timestamp will overflow in 32 bits systems!\r\n\r\n$timeLeft = $currentDate-&gt;diff($targetDate);\r\n\r\n$yearsLeft = $timeLeft-&gt;y;\r\n$monthsLeft = $timeLeft-&gt;m;\r\n$daysLeft = $timeLeft-&gt;d;\r\n$hoursLeft = $timeLeft-&gt;h;\r\n$minutesLeft = $timeLeft-&gt;i;\r\n$secondsLeft = $timeLeft-&gt;s;\r\n\r\necho \"Time left to Unix timestamp overflow in 32 bits systems:\r\n\";\r\necho \"| $yearsLeft years | $monthsLeft months | $daysLeft days | $hoursLeft hours | $minutesLeft minutes | $secondsLeft seconds |\";<\/pre>\n<p>As we can see, we can specify a date when instantiating <code>DateTime<\/code> class, or we cannot specify it in order to use the current datetime.<\/p>\n<h3>3.4. Increasing precision<\/h3>\n<p>In some scenarios, it could occur that the time stamp precision is not enough. For these occasions, we have available the <code>microtime()<\/code> function, which gets the current Unix time, with microseconds. Let&#8217;s see an example with this:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>datetime_with_microseconds.php<\/em><\/span><\/p>\n<pre class=\"brush:php\">&lt;?php\r\n\r\n$microtime = microtime();\r\n\r\nlist($microseconds, $seconds) = explode(' ', $microtime);\r\n\r\n$microseconds = str_replace('0.', '', $microseconds);\r\n\r\n$datetime = date('d-m-Y h:i:s');\r\n$datetime .= ':' . $microseconds;\r\n\r\necho \"Current datetime with microseconds: $datetime\";<\/pre>\n<p>For some reason, <code>microtime()<\/code> function returns a string with the following format: <code>&lt;microseconds&gt; &lt;seconds&gt;<\/code>, separated by a blank space. So, we have to split it.<\/p>\n<p>The microseconds are expressed as real number, so, we should remove the leading zero integer part. Then, we can manually add to the formatted datetime the microseconds part.<\/p>\n<p>The funny fact is that, actually, the date() function does support the microseconds formatter, &#8216;u&#8217;. But it&#8217;s not able to generate the microseconds. If you try to get a date using <code>date('d-m-Y h:i:s:u');<\/code>it will generate only zeros in the microseconds part. What were PHP developers thinking in?<\/p>\n<h3>3.5. Validating user introduced date<\/h3>\n<p>If we are having a web page where the user has to introduce same date, probably, we will use a JQuery plugin to allow the user select the date graphically. In any case, after performing any operations, we should ensure that the date is correct.<\/p>\n<p>If you try to calculate the time stamp of a nonsense date, for example, <code>40\/15\/2016<\/code>, you will receive the following time stamp: <code>1555279200<\/code>, with no error. And, if you try to calculate the date of that time stamp, you will receive a correct date, <code>14\/04\/2019<\/code>.<\/p>\n<p>Depending on the scenario, this can be something to check, or not. If you are expecting a date introduced by an user, normally, we want to ensure that it is actually a valid date expressed in human-readable format. Let&#8217;s see how we would validate it in the following example:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>validate_date.php<\/em><\/span><\/p>\n<pre class=\"brush:php; highlight:[15]\">&lt;?php\r\n\r\ndefine('DEFAULT_DATE_SEPARATOR', '-');\r\ndefine('DEFAULT_DATE_FORMAT', 'd' . DEFAULT_DATE_SEPARATOR . 'm' . DEFAULT_DATE_SEPARATOR . 'Y'); \/\/ 'd-m-Y'.\r\n\r\n\/**\r\n\u00a0* Checks the validity of the date, using \"checkdate()\" function. Leap years are also taken into consideration.\r\n\u00a0*\r\n\u00a0* @param $date The input date.\r\n\u00a0* @return True if the date is valid, false if it is not.\r\n\u00a0*\/\r\nfunction validateDate($date) {\r\n\u00a0\u00a0\u00a0 list($day, $month, $year) = explode(DEFAULT_DATE_SEPARATOR, $date);\r\n\r\n\u00a0\u00a0\u00a0 $validDate = checkdate($month, $day, $year); \/\/ Not a typo; the month is the first parameter, and the day the second.\r\n\r\n\u00a0\u00a0\u00a0 return $validDate;\r\n}\r\n\r\n\/\/ Flow starts here.\r\n\r\n$inputDate = $_GET['input-date'];\r\n$validDate = validateDate($inputDate);\r\n\r\nif ($validDate) {\r\n\u00a0\u00a0\u00a0 $response = \"The date $inputDate is valid.\";\r\n} else {\r\n\u00a0\u00a0\u00a0 $response = \"Error: the date $inputDate is not correct.\";\r\n}\r\n\r\necho $response;<\/pre>\n<p>Fortunately, PHP has a built-in function for this cases, named <code>checkdate()<\/code>, that checks the validity of a Gregorian date, considering also leap years. So, <code>29-02-2016<\/code> would be considered valid, while <code>29-02-2015<\/code> wouldn&#8217;t.<\/p>\n<p>The problem here is that we have to parse manually the date, to extract the day, month and year, and also to the specified format. If we use any other function to change the format, or to retrieve the date numbers, it would automatically fix the date, doing the same as we saw before the example, so we could not validate the date.<\/p>\n<h2>4. Summary<\/h2>\n<p>We have seen that saving dates in any human-readable format is not a good idea, because the same date can have many different representations, which will depend on the region. We have seen that Unix time format solves this, using a portable format, that does not rely on region or languages, and how to deal with this format in PHP.<\/p>\n<h2>5. Download the source code<\/h2>\n<p>This was an example of date formatting with PHP.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/PHPDateFormatExamples.zip\"><strong>PHPDateFormatExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example, we shall show how to deal with dates in PHP. As dates can be represented in many different ways. It is important to find a way that helps to avoid possible unexpected errors that may arise. For this example, we will use: Ubuntu (14.04) as Operating System. Apache HTTP server (2.4.7). PHP &hellip;<\/p>\n","protected":false},"author":160,"featured_media":930,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[144],"class_list":["post-12462","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-date"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Date Format Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this example, we shall show how to deal with dates in PHP. As dates can be represented in many different ways. It is important to find a way that helps\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Date Format Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this example, we shall show how to deal with dates in PHP. As dates can be represented in many different ways. It is important to find a way that helps\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-18T13:15:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T08:58:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Toni\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Toni\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/\"},\"author\":{\"name\":\"Toni\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/54a7be647b0b871cff41cbf3d2a95966\"},\"headline\":\"PHP Date Format Example\",\"datePublished\":\"2016-05-18T13:15:38+00:00\",\"dateModified\":\"2018-01-09T08:58:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/\"},\"wordCount\":1001,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"keywords\":[\"date\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/\",\"name\":\"PHP Date Format Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"datePublished\":\"2016-05-18T13:15:38+00:00\",\"dateModified\":\"2018-01-09T08:58:30+00:00\",\"description\":\"In this example, we shall show how to deal with dates in PHP. As dates can be represented in many different ways. It is important to find a way that helps\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/php\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Date Format Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/54a7be647b0b871cff41cbf3d2a95966\",\"name\":\"Toni\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21c1661474c78b4757355b8beef9ab1d14f490ee3a3e67392f4e618d36643d4c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21c1661474c78b4757355b8beef9ab1d14f490ee3a3e67392f4e618d36643d4c?s=96&d=mm&r=g\",\"caption\":\"Toni\"},\"url\":\"https:\/\/www.webcodegeeks.com\/author\/julen-pardo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Date Format Example - Web Code Geeks - 2026","description":"In this example, we shall show how to deal with dates in PHP. As dates can be represented in many different ways. It is important to find a way that helps","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/","og_locale":"en_US","og_type":"article","og_title":"PHP Date Format Example - Web Code Geeks - 2026","og_description":"In this example, we shall show how to deal with dates in PHP. As dates can be represented in many different ways. It is important to find a way that helps","og_url":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-05-18T13:15:38+00:00","article_modified_time":"2018-01-09T08:58:30+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","type":"image\/jpeg"}],"author":"Toni","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Toni","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/"},"author":{"name":"Toni","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/54a7be647b0b871cff41cbf3d2a95966"},"headline":"PHP Date Format Example","datePublished":"2016-05-18T13:15:38+00:00","dateModified":"2018-01-09T08:58:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/"},"wordCount":1001,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","keywords":["date"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/","url":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/","name":"PHP Date Format Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","datePublished":"2016-05-18T13:15:38+00:00","dateModified":"2018-01-09T08:58:30+00:00","description":"In this example, we shall show how to deal with dates in PHP. As dates can be represented in many different ways. It is important to find a way that helps","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/php\/php-date-format-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"PHP","item":"https:\/\/www.webcodegeeks.com\/category\/php\/"},{"@type":"ListItem","position":3,"name":"PHP Date Format Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/54a7be647b0b871cff41cbf3d2a95966","name":"Toni","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21c1661474c78b4757355b8beef9ab1d14f490ee3a3e67392f4e618d36643d4c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21c1661474c78b4757355b8beef9ab1d14f490ee3a3e67392f4e618d36643d4c?s=96&d=mm&r=g","caption":"Toni"},"url":"https:\/\/www.webcodegeeks.com\/author\/julen-pardo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/12462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/160"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=12462"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/12462\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/930"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=12462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=12462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=12462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}