21492 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1157 Views |
-
dateformat full month YYYY

17 June 2011 at 5:03am
Hi all,
I thought this would be an easy thing to do but after banging my head against the wall till it bled I now have no choice but to seek your help.
I want the dates from the 2nd tutorial to display as e.g. "April 2010" instead of 04 2010
I thought it would be as easy as changing MM YYYY to something different in this line
$dateField->setConfig('dateformat', 'MM YYYY');
but haven't been able to figure it out.
Can this be done? I'm not very experienced as a developer so I hope someone might have a solution
Thanks for looking
-
Re: dateformat full month YYYY

17 June 2011 at 7:11am
Hi ambient.
If your problem is just the output, you could try this in your template (themes/tutorial/templates/Layout/ArticlePage.ss):
Instead of this...
$Content
<div class="newsDetails">
Posted on $Date.Nice by $Author
</div>
...try this:
...
$Content
<div class="newsDetails">
Posted on $Date.Month $Date.Year by $Author
</div>
...For more methods have a look at the Date Class in /sapphire/core/model/fieldtypes/Date.php
Cheers
Christian -
Re: dateformat full month YYYY

18 June 2011 at 12:00am
Christian you are a scholar and a gent
That worked perfect, thank you so much
-
Re: dateformat full month YYYY

19 June 2011 at 11:31pm
Dates are confusing
$dateField->setConfig() is used when setting the default format for display in a Date field within a form as in
$dateField = new DateField( 'MyDate', 'Soeme date');
$dateField->setConfig('dateformat', 'MM yyyy');To format a date for output in your Template, Christians post of course is the way to go
If for some reason you wanted to format a date from within your Page controller, you'd could create a Date object first, then use its methods. Something like this:
function getMyDateNice() {
return $this->obj('MyDate')->Nice();
} -
Re: dateformat full month YYYY

11 July 2011 at 4:50am
Hi,
can you tell me how to use this function to get an date output like this
DD. Month YYYY.Thanks Benni
-
Re: dateformat full month YYYY

12 July 2011 at 12:08am
Hi Benni,
I didn't use the function in the end as I only wanted the date to output a certain way.
If thats all you want to then I would suggest using Christians technique.
In your ss file something like
$Date.DayOfMonth $Date.Month $Date.Year
You can see more methods of the Date Class in /sapphire/core/model/fieldtypes/Date.php
-
Re: dateformat full month YYYY

12 July 2011 at 3:31am
Hi,
i looked up the code in "/sapphire/core/model/fieldtypes/Date.php"
edit line 47 like thisfunction Nice() {
if($this->value) return date('d. F Y', strtotime($this->value));
}and everything works fine
thx ambient
| 1157 Views | ||
|
Page:
1
|
Go to Top |



