Output of Date Picker Field

Permalink Browser Info Environment
Hi Jordan,

I'd like to create a super simple news block (see attached screenshot).

Designer Content is the perfect tool for doing that, but I have one problem - the date must be output like this:

<div class="news-date">
  <span class="news-day">15</span>
  <span class="news-month">Jan</span>
  <span class="news-year">2012</span>
</div>


Of course, I could use three separate Text Boxes for day, month, and year. But I would prefer to use a single Date Picker Field.

Is there a (simple) way to use the Date Picker Field and get my desired output?

Thanks a lot for your answer!
Karl

1 Attachment

Type: Discussion
Status: New
karlertl
View Replies: View Best Answer
kupakabra replied on at Permalink Reply
kupakabra
Aloha,
IMO one of the ways to get this done is to add date normally, with date picker, enclosed within some div, and then crawl the document with jquery looking for this div, and then, enclosing first two characters(15) with approperiate span, and next three(Jan) with another span etc... :)
jordanlev replied on at Permalink Best Answer Reply
jordanlev
The easiest way to format dates upon output is to modify your block's view.php file, take the $field_#_date_value (where "#" is the field number in your particular block -- e.g. $field_1_date_value, $field_2_date_value, $field_7_date, etc.), convert it to a time value (using php's strtotime() function), then keep feeding that time value to php's date function.

For example, if the date field in your block is called $field_3_date_value, you could do this in your block's view.php file:
<?php $timestamp = strtotime($field_3_date_value); ?>
<div class="news-date">
  <span class="news-day"><?php echo date('j', $timestamp); ?></span>
  <span class="news-month"><?php echo date('M', $timestamp); ?></span>
  <span class="news-year"><?php echo date('Y', $timestamp); ?></span>
</div>


Seehttp://php.net/date for a full list of all the formatting strings you can pass into the date function.
karlertl replied on at Permalink Reply
karlertl
Perfect, Jordan! :-)

... and here's my solution for anyone who needs this in German date format:

1. Put this in your config/site.php:
setlocale('LC_TIME', 'de_DE');


2. Change Jordan's code slightly:
<?php $timestamp = strtotime($field_3_date_value); ?>
<div class="news-date">
  <span class="news-day"><?php echo strftime('%e', $timestamp); ?></span>
  <span class="news-month"><?php echo strftime('%b', $timestamp); ?></span>
  <span class="news-year"><?php echo strftime('%Y', $timestamp); ?></span>
</div>
tsilbermann replied on at Permalink Reply
tsilbermann
Thanks Guys,

exactly what I was looking for :-)

setlocale('LC_TIME', 'de_DE');


shows german date format.

Anyone knows a solution to show the right date format on a multilingual site (en/de)?

Best Regards

Torsten

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.