Timestam to Date

Timestam to Date

by Aditya Nigam -
Number of replies: 4


  • Who to extract data with respect to date?
  • How to see timestamp in Date format or in Time format (for ex dd/mm/yyyy hh:mm)?

Average of ratings: -
In reply to Aditya Nigam

Re: Timestam to Date

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
If you are running an SQL query, you have the ability to reconfigure the appearance of the date to whatever you wish.
In reply to Aditya Nigam

Re: Timestam to Date

by Luis de Vasconcelos -
How are you extracting the date? In a SQL query or in a plugin?

For SQL, try something like:

    DATEADD(s, mdl_your_table.timecreated, '19700101 00:00:00:000') AS yourdate

or

    CAST(DATEADD(s,mdl_your_table.timecreated,'19700101 00:00:00:000') AS date) AS yourdate


The "19700101 00:00:00:000" should reflect your own timezone - i.e. UTC + or - X hours.
If you're using MySQL then you could always use UNIX_TIMESTAMP() instead of DATEADD()...
In reply to Luis de Vasconcelos

Re: Timestam to Date

by Joost Elshoff -
Picture of Particularly helpful Moodlers Picture of Testers
Adding ‘from_unixtime’ to that part of the query also works… 
Average of ratings: Useful (1)
In reply to Joost Elshoff

Re: Timestam to Date

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
I like using this form of the SQL command that puts the date into a format that Excel likes.

from_unixtime(timeopen, "%m/%d/%Y %h:%i:%s %p")
Average of ratings: Useful (2)