3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 8143 Views |
-
$date.nice

9 March 2009 at 5:30am
Hi,
This is probably something really simple to do, but i am not so good at php yet $date.nice outputs as "17/02/09" but what i want to do is output it separately. like day of the month as a number, month as 3 letter word. Dont really need the year so the example above would be "17 Feb" and i want to be able to add separate css to them.
Thanks in advance
FireMe!
-
Re: $date.nice

10 March 2009 at 9:10am Last edited: 27 March 2009 7:13am
Hi,
Does $date.format(%e %b) help?
Or, if you want the date and month to be styled differently, you could do:
<span class="day">$date.format(%e)</span> <span class="month">$date.format(%b)</span>
You can find a list of valid date formatting codes on http://us.php.net/strftime. At present, you can't use commas inside the call to format, however, I'm hoping that will change.
Edit: Actually, the formatting codes may be found at: http://us2.php.net/date
Ben
-
Re: $date.nice

10 March 2009 at 10:10pm
i am really missing something. I can't figure out where those special functions are defined....like if i try and use $date.format(%e %b) in any of my Layout templates i just error out.
:Fatal error: Call to a member function XML_val() on a non-object:i can't figure out how to use any php...after lots of reading i guess it needs to be adding to the page controller as a function, but i don't understand things like $date, or how to access it...can anyone shed some light? thanks!
-
Re: $date.nice

11 March 2009 at 2:11am
Hi,
Have you seen http://doc.silverstripe.org/doku.php?id=date&s=format? Is $date defined as a property in your page's model (e.g. in the static $db array)?
Yes, you are correct that PHP code needs to be in the controller (or model), not in the template. However, ".format" on a date property should work in a template.
Ben
-
Re: $date.nice

11 March 2009 at 7:20am Last edited: 11 March 2009 7:22am
<span class="day">$date.format(%e)</span> <span class="month">$date.format(%b)</span>
didnt work for me for some reason, its displayed as %Europe/London %b
but i changed it to.<span class="day">$date.format(d)</span> <span class="month">$date.format(m)</span>
and that displayed as 17 Feb
anyways thanks for your help, your code layout helped out alot,i am not to good at php/mysql
FireMe
-
Re: $date.nice

11 March 2009 at 7:30am
Sure thing. Sorry about those extra percent signs. I forgot that they are left off when in a template.
-
Re: $date.nice

8 May 2010 at 4:17am
Thanks for the help here. Saved me some time last night. Just a note:
That link to the docs doesn't seem to be working (anymore?). After I already solved my issue, I finally found what I was looking for in the docs.
http://api.silverstripe.org/2.4/sapphire/model/Date.html
It's a big mess to read, but with functionality you are "sure" is there, it can be very helpful.
Also, in plain ol' php you can easily add extra text to the formatting. Within SilverStripe however, adding commas or other symbols can cause issues. It was shown by others but I had to format like this: $Date.format(l), $Date.format(M d), $Date.format(Y) to get "Thursday, May 13, 2010"
| 8143 Views | ||
|
Page:
1
|
Go to Top |


