I'm using Drupal 7.38 and I'm trying to print the creation date of a node in 3 separate divs, to be able to format it appart, so I created the following on the node.tpl.php:

            <div class="fecha">
                <div class="mes"><?php print $date; ?></div>
                <div class="mes"><?php print format_date($node->created, 'custom' , 'M'); ?></div>
                <div class="dia"><?php print format_date($node->created, 'custom' , 't'); ?></div>
                <div class="año"><?php print format_date($node->created, 'custom' , 'Y'); ?></div>

But, when I go to the result page I've got this:

MAR, 07/28/2015 - 16:20




So, why is the day showing the incorrect date???



You should use d for the day of the month. Using t php displays the number of days for the given month. Reference: http://php.net/manual/en/function.date.php

| improve this answer | |
  • Never mind. Those type of mistakes can happen to anyone. They are like the lost keys in front of you :) – Gregory.K Aug 13 '15 at 21:29

t isn't the correct value for format_date when using the day. The custom option for format_date uses PHP's date syntax. As such t outputs the number of days in that month. What you want to use is j to list the day in that month.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.