How does date / time in DB convert to real Date / Time?

How does date / time in DB convert to real Date / Time?

by Caz M -
Number of replies: 8
Hi,  I don't know if this is the right place to post, but I couldn't find anywhere more appropriate.  I was wondering what the conversion is for the 'time' in the mdl_log table (e.g. 1130887594) to real date and time?
Thanks
Caz
Average of ratings: -
In reply to Caz M

Re: How does date / time in DB convert to real Date / Time?

by Hans de Zwart -
Somebody correct me if I am wrong, but this is a Unix timestamp (I think the amount of seconds since 1-1-1970). In PHP there are couple of functions to convert this to something understandable. See for example the date() function.

Regards, Hans
Average of ratings: Useful (1)
In reply to Caz M

Re: How does date / time in DB convert to real Date / Time?

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
And if you want to convert the values manually during testing (I do sometimes), no need to waste time using PHP scripts; there are online converters, such as:

http://www.onlineconversion.com/unix_time.htm

It might be argued that using the database's time format would be better practice than just storing the Unix time (this would allow you to see the time in normal format just by looking at the database). I would personally take that position, but there are arguments for doing it the way Moodle does, as it relies less on database features.

--sam
In reply to sam marshall

Re: How does date / time in DB convert to real Date / Time?

by Richard M -
It's also possible to do this if you have access to a Unix command line with the command:

date -d @#NUMBER#

ie:

[root@webbox root]# date -d @1130887594
Wed Nov 2 07:26:34 WST 2005

Or you can use the built-in MySQL functions
UNIX_TIMESTAMP()
FROM_UNIXTIME()

in the context:

select UNIX_TIMESTAMP(UnixStored_Field) from tblMyDatabase where 1=1
Cheers

Richard
In reply to Caz M

Re: How does date / time in DB convert to real Date / Time?

by Thisum Buddhika -

if you use moodle 1.9 , there is a moodle function    userdate($time)

hope this answers your problem...

Average of ratings: Useful (2)
In reply to Caz M

Re: How does date / time in DB convert to real Date / Time?

by Adam Landow -

I use this function I found at http://www.weberdev.com/get_example-3113.html

function GetTimeStamp($MySqlDate)
{
/*
Take a date in yyyy-mm-dd format and return it to the user in a PHP timestamp
Robin 06/10/1999
*/

$date_array = explode("-",$MySqlDate); // split the array

$var_year = $date_array[0];
$var_month = $date_array[1];
$var_day = $date_array[2];

$var_timestamp = mktime(0,0,0,$var_month,$var_day,$var_year);
return($var_timestamp); // return it to the user
}

and it works just fine smile

In reply to Adam Landow

Re: How does date / time in DB convert to real Date / Time?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That is not relevant to Moodle. Moodle uses unix timestamps, not MySQL datetimes.

Average of ratings: Useful (1)