Solved

Converting epoch to h:mm within MySQL Query

Posted on 2012-03-31
6
342 Views
Last Modified: 2012-07-12
Simply query starts like...

---
SELECT apps_zapata_walks.id, apps_zapata_walks.walker_fname, apps_zapata_walks.walker_lname, apps_zapata_walks.walker_email, mdl_user.firstname as TeacherFirstName, mdl_user.lastname as TeacherLastName, mdl_user.email as TeacherEmail, mdl_groups.`name` as CampusName, apps_zapata_walks.co_teacher, apps_zapata_walks.date_of_walk, apps_zapata_walks.auto_time_in, apps_zapata_walks.auto_time_out,
---

How can I format the apps_zapata_walks.auto_time_in as hh:m within the query?

something like...

date('gia',apps_zapata_walks.auto_time_in) ???

Of course I doubt that would work but I am having trouble finding out what will.

Thank you in advance!
0
Comment
Question by:smetterd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 167 total points
ID: 37791913
Use this, instead of the plain column name:

EXTRACT(HOUR_MINUTE FROM apps_zapata_walks.auto_time_in) AS auto_time_hh_mm

Open in new window


Notice you have to alias it like I did.
0
 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 167 total points
ID: 37792440
epoch is in UTC, you may want to convert the time into a certain time zone.

http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html
FROM_UNIXTIME() fits better to the epoch unix timestamp.

SELECT FROM_UNIXTIME(auto_time_in,'%H:%i') as auto_time_hh_mm

Open in new window


The reference also says:
The value is expressed in the current time zone
That is you get HH:MM in the time zone of the MySQL Server.

And you can use date(), but not within the query, mysql runs mysql functions, not php functions. But you can query the unix timestamp and when displaying it can use the PHP date() with the data fetched unchanged.

Bye, Olaf.
0
 
LVL 11

Assisted Solution

by:SANDY_SK
SANDY_SK earned 166 total points
ID: 37792491
did you try

 select DATE_FORMAT(apps_zapata_walks.auto_time_in,"%h:%i")  

Open in new window

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37793771
Topics: MS SQL Server, PHP Scripting Language, SQL Query Syntax
Please request that the MS SQL Server topic be removed as it does not apply.
0
 
LVL 2

Author Comment

by:smetterd
ID: 37897082
I have fought with this for some time, but still no love. I am going to make a movie of exactly what I am trying and post it by the end of the day. Thanks for hanging in there...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question