mysql timestamp ceiling to 5 minutes

Hai,

Is there any function ( or an efficient way) to get the following functionality in mysql.

2005-11-10 22:31:12 as 2005-11-10 22:35
2005-11-10 22:34:13 as 2005-11-10 22:35
2005-11-10 22:43:13 as 2005-11-10 22:45
2005-11-10 22:47:13 as 2005-11-10 22:50.

Its nothing but a ceiling based on 5 minutes.

Please help.

regards,
MSKumar
mskumar_apkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

virmaiorCommented:
http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html provides the majority of things that would help here..
I'm not seeing any rounding functions

but try this:

(as if your field was called mytime)
SELECT CONCAT(EXTRACT(YEAR_MONTH, mytime) , EXTRACT(DAY_HOUR,mytime),(EXTRACT(MINUTE,mytime) DIV 5)*5 ) FROM mytable

the use of the integer DIV operator makes this require MySQL 4.1

SELECT CONCAT(EXTRACT(YEAR_MONTH, mytime) , EXTRACT(DAY_HOUR,mytime),(CEIL(EXTRACT(MINUTE,mytime) / 5)*5 )) FROM mytable

which should work in any v4 or 3.23+
0
PetrTomenendalCommented:
or you can try this:
select *,FROM_UNIXTIME(CEIL(UNIX_TIMESTAMP(datum)/300)*300,'%Y-%m-%d %H:%i') from test;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mskumar_apkAuthor Commented:
Hai,

thanks for ur reply. both works well. splitted the points. once again thanks for ur help.

regards,
MSKumar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.