abdellatif zoumhane abdellatif zoumhane -4 years ago 109
MySQL Question

How to get data of the current time from mysql database

I have data per day in my database mysql. What I want to do is to select the km field in the current time in the day minus the km field in start of the day (current day time :00:00 am).
I tried this but it didnt work:

SELECT km from position where serverTime=startOfTheDay

SELECT km from position where serverTime=currentTime()


These two requests don't work. I just need an idea of what I need to do.

Also, I need to minus the last km from the first one, help please??

enter image description here

Answer Source

You can try this approach - it finds the difference between the smallest and largest km for each day.

select min(serverTime) as start, max(serverTime) as stop, max(km) - min(km) as km_difference
  from position
 group by date(serverTime);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download