snipt

Ctrl+h for KB shortcuts

PHP

How to format dates in drupal

1
2
3
4
5
<?php

print format_date(strtotime($node->field_event_date[0]['value']), 'custom', 'D, j M, Y \a\\t G:i' );

?>
https://snipt.net/embed/e20583cc48a355ace529b8cc52920655/
/raw/e20583cc48a355ace529b8cc52920655/
e20583cc48a355ace529b8cc52920655
php
PHP
5
2019-07-20T11:53:59
True
False
False
/api/public/snipt/4997/
how-to-format-dates-in-drupal
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">print</span> <span class="nx">format_date</span><span class="p">(</span><span class="nb">strtotime</span><span class="p">(</span><span class="nv">$node</span><span class="o">-&gt;</span><span class="na">field_event_date</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;value&#39;</span><span class="p">]),</span> <span class="s1">&#39;custom&#39;</span><span class="p">,</span> <span class="s1">&#39;D, j M, Y \a\\t G:i&#39;</span> <span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
date, drupal, format