Databases: Date format

Databases: Date format

by David Gil -
Number of replies: 5

How can I get give a format to dates or times in any of the moodle tables such as mdl_log. I am trying to create a SQL querry, using phpmyadmin and mysql, but I can not print the date sucessfully. I can only show the column time but when I try to use any of the SQL functions for dates there is always a error.

Average of ratings: -
In reply to David Gil

Re: Databases: Date format

by Douglas Wright -
There is a PHP function - getdate() - that will convert the timestamps to a more readable format.

http://us2.php.net/manual/en/function.getdate.php

There is not a MySQL function that I am aware of that will convert the Unix time stamp to a "normal" date  string.
In reply to Douglas Wright

Re: Databases: Date format

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Even better, in moodlelib.php there is userdate. You typically use it like:

$date = userdate($transition->time, get_string('strftimerecent'));

There are various date formats defined in the lang file, of if you leave out the format, it uses a sensible default.

Tim.

Average of ratings: Useful (2)
In reply to Tim Hunt

Date format

by David Gil -

Many thanks for your help but how will you using Mysql and phpMyAdmin will give format to the date lastaccess column?.

SELECT `username`,CONCAT(`firstname`,' ',`lastname`) AS name,`email`,`lastaccess` FROM `mdl_user`

In reply to David Gil

Re: Databases: Date format

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Ah, I see, I did not read the question carefully enough. You need the FROM_UNIXTIME function

http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#id2682338
In reply to Tim Hunt

Re: Databases: Date format

by Cornel van Lingen -

What about using this:

select date_add('1970-01-01',interval round(timemodified/60/60/24) day) from mdl_quiz_grades;

If I understand your question correctly