Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8169207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:46:36+00:00 2026-06-06T20:46:36+00:00

For doing some statistics on my incoming data on webserver I do some ETL

  • 0

For doing some statistics on my incoming data on webserver I do some ETL work on this data. So I aggregate some thing based on quarter hours. I.e.:

inserted  | tstamp
8:00        8:00
8:09        8:00
8:16        8:15
8:29        8:15
8:42        8:30
8:45        8:45
8:59        8:45
9:01        9:00

The columns above are datetime column, which also contain a date (I left it out only for demonstration purposes). The job runs every 3 minutes via cron and takes only data from last 3 minutes. Now, when the cron jobs crash while working, there is the risk, that a time slot contains wrong data when the jobs restarts next time. So I want the job to begin at last slot. I.e. when the job runs at 08:24 last and crash it should start again at 08:15.

My question is now, is there a simple MySQL statement which gives me the last time slot before the actual time?

The statement I’m using in ETL to determine actual time slot is

CONCAT(
    DATE_FORMAT(a.inserted, '%Y-%m-%d %H:'),
    IF(MINUTE(a.inserted)<15,'00',
        IF(MINUTE(a.inserted)<30,'15',
        IF(MINUTE(a.inserted)<45,'30',
        '45'))
    ),
    ':00'
) AS tstamp

Could this be done in a more elegant way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:46:37+00:00Added an answer on June 6, 2026 at 8:46 pm

    You can use unix_timestamp() to get the current time in number of seconds since 1970. The last 3-minute interval is that time modulo 3*60 seconds:

    select  from_unixtime(unix_timestamp() - mod(unix_timestamp(), 180))
                as StartOfInterval
    ,       from_unixtime(unix_timestamp() - mod(unix_timestamp(), 180)-180) 
                as StartOfLastInterval
    

    Live example at SQL Fiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing some statistics work with Stata recently and not enjoying it
I've started doing more and more work with the new Mathematica statistics and data
I'm doing some statistics based on a database of states. I would like to
In doing some bioinformatics work, I've been pondering the ramifications of storing object instances
I'm doing some statistics calculations. I need them to be fast, so I rewrote
I am doing some performance work in my unit tests and wondering if it
I ended up doing some emergency PM stuff at work and I would like
I have some data for my sites statistics in a SQL DB: date: visits:
Doing some jquery animation. I have certain divs set up with an attribute of
Doing some homework here (second assignment, still extremely green...). The object is to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.