Function userdate: I can't format date string

Function userdate: I can't format date string

Quincy Weston གིས-
Number of replies: 3

Hi moodlers....

I'm building a block using the "$USER-> lastlogin" container, among others. I'm using the following code to format its content:

'<div>'.get_string('lastlogin').'<br>'.userdate($USER->lastlogin).'</div>'

This displays the date in a very long format, example: Sábado, 26 de julio de 2008, 01:38 (My server locale configuration is es_utf8).

I need a shorter format,  example: Sáb, 26 de jul de 2008, 01:38 (like the forums lastpost field). Please, What are the format options that I must use in the userdate function? Thanks...

QW

དཔྱ་སྙོམས་ཀྱི་སྐུགས་ཚུ།: -
In reply to Quincy Weston

Re: Function userdate: I can't format date string

Gary Anderson གིས-
Qwincy:

You can see the function definition for userdate in the file /lib/moodlelib.php.

The second argument to the command allows you to specify the formatting. Note that it uses the arguments from the php command strftime which you can find at http://us.php.net/strftime.

You may also want to do a file search for the userdate function to see how it is being used in other parts of the code.

Good luck,

--Gary
In reply to Quincy Weston

Re: Function userdate: I can't format date string

Eloy Lafuente (stronk7) གིས-
Core developers གི་པར Documentation writers གི་པར Moodle HQ གི་པར Particularly helpful Moodlers གི་པར Peer reviewers གི་པར Plugin developers གི་པར Testers གི་པར
Yup, that second parameter specifies the "strftime" format.

Also, be noted that there are a bunch of "standard" date and time formats predefined in the lanconfig.php files (inside each lang/xx directory).

And those are the preferred ones to be used within Moodle, with something like:

userdate($time_to_format, get_string('strftimeXXX'));

instead of using "harcoded" formats. The main advantage of this: your formatted date will we showed properly in any language (respecting their particularities).

Ciao དགའ་འཛུམ་

In reply to Eloy Lafuente (stronk7)

Re: Function userdate: I can't format date string

Quincy Weston གིས-

Thank you very much Stronk7....

I used:

<div>'.get_string('lastlogin').'<br>'.userdate($USER->lastlogin, get_string('strftimerecentfull')).'</div>'

and works fine approve