Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MYSQL: Extract Date from Timestamp Field

Posted on 2008-10-02
1
Medium Priority
?
1,539 Views
Last Modified: 2012-06-27
I have a table that has only two fields: dtmDateTime timestamp field; fData float field.  I want to group data by max, min, avg by date.  How can I do this via SQL SELECT.  I tried select convert(varchar,dtmdatetime,104) from tablename; but it does not work - error is returned for convert.  Any help extracting the date from the timestamp field would be appreciated
0
Comment
Question by:DCCoolBreeze
[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
1 Comment
 
LVL 1

Accepted Solution

by:
fReAkCoRp earned 500 total points
ID: 22629836
To select the Date from the filed you can use the Date Function you can used like this example:
SELECT date(dtmDateTime) as DateField,fData as DataField FROM test t;
for the max , min and avg you can go from this examples:
Group by :
SELECT date(dtmDateTime) as DateField,fData as DataField, count(*) as CountField FROM test t group by DateField
MAX and MIN
SELECT min(date(dtmDateTime)) as DateField, fData as DataField, count(*) as CountField FROM test t
group by DataField
for and avg you can go like this
SELECT sum(fData)/count(*) as from FROM test t where date(dtmDateTime)=date('2001-01-01');
you can use the sum function and add all the fData and divided by the count of data that matches the date you want to have your query based on.
this are just some examples but if you can post more info in what are you going to do maybe I can help you more.
Hope this works.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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