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:
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
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
Type: | Discussion |
---|---|
Status: | New |
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:
Seehttp://php.net/date for a full list of all the formatting strings you can pass into the 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:
Seehttp://php.net/date for a full list of all the formatting strings you can pass into the date function.
Perfect, Jordan! :-)
... and here's my solution for anyone who needs this in German date format:
1. Put this in your config/site.php:
2. Change Jordan's code slightly:
... 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>
Thanks Guys,
exactly what I was looking for :-)
shows german date format.
Anyone knows a solution to show the right date format on a multilingual site (en/de)?
Best Regards
Torsten
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
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... :)