×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Grouping by time intervals

## Grouping by time intervals

(OP)
I am attempting to group records by 12 minute intervals. I.E. 12:00pm-12:12pm, 12:13pm-12:25pm, etc. I am currently grouping in 10 minute intervals...although the current method won't exactly work for 12. Can anyone give some advice on this? See the SQL below:

#### CODE

SELECT TIMESTAMP(LEFT(char(nvs.TXN_DT_TM),13) || '.' || RIGHT(LEFT(char(nvs.TXN_DT_TM),15),1) || '0.00.000000') as YYYY_MM_DD_HH_10MM,
count(DISTINCT nvs.UZRL) AS "Unique Users",
cast(count(DISTINCT nvs.UZRL) as float)/6 AS "Labor Hours"
FROM db.table nvs
WHERE nvs.TXN_DT_TM >= '2011-01-01-00.00.00' and date(nvs.TXN_DT_TM) >= (current date)
AND (nvs.MVKD = 'RDSC' AND nvs.PFHS = 'Y')
GROUP BY TIMESTAMP(LEFT(char(nvs.TXN_DT_TM),13) || '.' || RIGHT(LEFT(char(nvs.TXN_DT_TM),15),1) || '0.00.000000')

### RE: Grouping by time intervals

Try this:

#### CODE

SELECT TIMESTAMP(LEFT(CHAR(CURRENT_TIMESTAMP),13) || '.' ||
LEFT(CHAR(INTEGER(MINUTE(CURRENT_TIMESTAMP)/12)+1),1)
|| '0.00.000000'), CURRENT_TIMESTAMP
FROM SYSIBM.SYSDUMMY1

I've added the timestamp at the end so you can see what's doing. It breaks the minutes into 12 minute chunks, which looks to me as it will work but I haven't fully tested it.

Let me know if it fits.

Marc

### RE: Grouping by time intervals

Thinking about it, you will need to remove the +1 on the second line of code as that will give you a timestamp of 60 during the last 12 minute period which is invalid.

Marc

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!