General developer forum

 
 
Picture of Erik Gotera
Transform timestamp to date in Moodle 2.3
 

Hello,

I want to change the value that is stored in the database (timestamp) and transform it to Date Time. For example:

DueDate in Database -> 1354632000

DueDate in Moodle -> Due date: Tuesday, 4 December 2012, 2:40 PM

Is there a function for this?
Someone could help me?
thank you very much

 
Average of ratings: -
Picture of Lavanya Peddapeta
Re: Transform timestamp to date in Moodle 2.3
 

SYNTAX :select (FROM_UNIXTIME(fieldname,"format string") from tablename
Example :select id,(FROM_UNIXTIME(startdate,"%Y")) as startdate from pauls_dp_plan

 
Average of ratings: -
Picture of Paul Holden
Re: Transform timestamp to date in Moodle 2.3
Group Particularly helpful Moodlers

Use the userdate() method from lib/moodlelib.php

 
Average of ratings:Useful (1)
Picture of Patrick Pollet
Re: Transform timestamp to date in Moodle 2.3
Group Particularly helpful Moodlers

userdate() is definitively a much better solution since FROM_UNIXTIME is known only on MySQL databases to my knowledge.

Cheers

 
Average of ratings:Useful (1)
Picture of Erik Gotera
Re: Transform timestamp to date in Moodle 2.3
 

Perfect, using userdate () does what I want.
Thank you very much to all.

 
Average of ratings: -