1

I have the database where I have two columns - date (incl. time) and minutes - as follows:

Open_Time                           Minute
2013-01-01 09:00:00.000    1
2013-01-01 09:01:00.000    1
2013-01-01 09:02:00.000    1
2013-01-01 09:03:00.000    1
2013-01-01 09:04:00.000    1
2013-01-01 09:05:00.000    1

How to count the minutes between the first and last date time?

select COUNT(Minute)
from test_table
where open_time between '2013-01-01 09:00:00.000' and '2013-01-01 09:05.000'

does not work for me.

I will need to count the minutes as current time - open time in the future.

Thank you for any feedback!

4 Answers 4

3

for mysql may be can use :

SELECT TIMESTAMPDIFF(MINUTE,'2013-01-01 09:00:00.000','2013-01-01 09:05.000') ; // return result as minutes

read here : http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

Sign up to request clarification or add additional context in comments.

1 Comment

SELECT TIMESTAMPDIFF(MINUTE,'2013-01-01 09:00:00.000','2013-01-01 09:05.000') will also return time difference in minute.
1

The SQL looks fine although it returns 6. Did you want that or did you want 5? You could always just start your SELECT criteria from 09:01:00.000 if that's what you want.

SQLfiddle here: http://sqlfiddle.com/#!2/d3f13/2

1 Comment

Thanks, there is probably problem in my db as the values are not properly sorted day by day. So my command should work.
1

I am not getting exactly what you want. But if want to extract minute from your date then use following query.

SELECT EXTRACT(MINUTE FROM Open_Time) FROM test_table;

SELECT EXTRACT(MINUTE FROM Open_Time)-10 FROM test_table;

Above query will give only difference in minute. so check you DAY,HOUR,MINUTE,SECONDS based on your criteria

5 Comments

Thank you for the reply. What I will need is the following - counting number of minutes per time interval. I will count SLA in this way from my auxiliary table. So I will need to count the number of minutes between current time (from the auxiliary table) and open time. So if open time was 20.6.2013 at 09:00, I will need to count the number of minutes between today and this date time. Makes sense?
It's my pleasure if i help you.
mysql> SELECT TIMESTAMPDIFF(MINUTE,'2013-06-20 09:00','2013-07-01 15:12');
OK... No problem but i haven't much experience in oracle as I learnt in my college days. And after that i never used that. Also please add tag for oracle in your question
Sure, no prob. Thanks anyway :)
0

In sql server you can use DATEDIFF function,wich accept folowing parameters: DATEDIFF(datepart,startdate,end date) and returns count(int) between specified date boundaries for selected datepart,so you could use something like this:

select DATEDIFF(mi,MIN(opentime),MAX(opentime)) AS 'minutes'
from test_table
where open_time between '2013-01-01 09:00:00.000' and '2013-01-01 09:05.000'

You also cloud count minutes from column "minutes",but it will be very hard to count them with current date(unless,every time when counting you insert current time in the table,or create temp table) !

3 Comments

Thanks. That might be useful. It will be hard later on. I ll have to calculate the amount of minutes from open time (of ticket) to now. I dont know where to start yet. E.g. the ticket has open time 20.6.2013 09:00, I ll need to calculate the time interval (minutes) from this date til now. However the main problem here I also have to take the work hours 09-17 into account. Thats why I have temp table (example in my first question) with work hours and holidays marked. With a bit of help this temp table I wanted to count the total minutes.
Hm,then you should use some mathematics to extract only work minutes from total number of minutes.If you can,probably it will be easier to write that logic in application !
I have that .. I have a table (example above) where the years are split day by day (excl weekends and holidays), minute by minute so one day has 481 rows (09 - 17) .. the hard part will be to do the counting in ETL so I count count the difference between open time and current time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.