How to format Date field

How to format Date field

by John Kouraklis -
Number of replies: 3
Hi all,

I have a Date field in a database and I am trying to customise the list view.

When I use the relevant field, I get this: 15 December 2014. How can I customise the output to be eg. 15/12/2014?

Thanks

John


Average of ratings: -
In reply to John Kouraklis

Re: How to format Date field

by Itamar Tzadok -

The Date field of the Database uses the format '%d %B %Y' which is defined in the lang string strftimedate. You can change this lang string to something like '%d/%m/%Y'. Of course this will affect every other component that displays dates formatted with this lang string, but there are only a few (I found 9 all over Moodle) so it should be fairly safe. smile


Average of ratings: Useful (1)
In reply to Itamar Tzadok

Re: How to format Date field

by John Kouraklis -

Hi and thanks for the reply.

I was thinking to take the field from the database and format it. I present it in a table.

But I don't know how to get the field and do the manipulation. Even with JavaScript I don't know how to access the dB field

In reply to John Kouraklis

Re: How to format Date field

by Itamar Tzadok -

In the tempalte, enclose the field pattern with a div element with css class, something like:

<div class="myDate">[[Date] ]</div>

Then the javascript can look for all the these elements by the css selector, get their innerHTML, parse the date string and replace it with a reformatted one.

hth smile