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

  • SEARCH
  • Home
  • 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 8665727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:33:19+00:00 2026-06-12T17:33:19+00:00

I would like to insert timestamp values of 3 minute steps (given a start

  • 0

I would like to insert timestamp values of 3 minute steps (given a start and end date) into a table with just one timestamp column.

I currently switch from sql server to mysql. I would know how to do it for the former database in SQL but am not sure about the latter. Thanks.

This is my current (not working) miserable attempt:

DELIMITER //
CREATE PROCEDURE test()
begin
    declare StartTS TIMESTAMP DEFAULT null;
    declare EndTS TIMESTAMP DEFAULT null;

    set StartTS = '2012-01-01 00:00:00';
    set EndTS = '2014-01-01 00:00:00';

    start transaction;
      while StartTS < EndTS do
        insert into timestamps (TimeStampEntry) values (StartTS);
        SET StartTS  = StartTS  + INTERVAL 3 MINUTE;
      end while;
      commit;
end
//

DELIMITER ;

call test();

PS:

create table TimeStamps (
        Id INTEGER NOT NULL AUTO_INCREMENT,
       TimeStampEntry DATETIME,
       primary key (Id)
    )

current sproc:

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `myProc`(IN t1 timestamp, IN t2 timestamp)
BEGIN

  WHILE t1 <= t2 DO
INSERT INTO timestamps (TimeStampEntry) Values (t1)  ;
    SET t1 = DATE_ADD(t1, INTERVAL 180 SECOND);
    #SET t1 = t1 + INTERVAL 180 SECOND;
  END WHILE;
END

call:

CALL myProc('2010-01-01 00:00:00', '2014-01-01 00:00:00');
  • 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-12T17:33:21+00:00Added an answer on June 12, 2026 at 5:33 pm

    try something like this:

    CREATE PROCEDURE myProc(IN t1 timestamp, IN t2 timestamp)
    BEGIN
    
      WHILE t1 <= t2 DO
    INSERT INTO test (ts) Values (t1)  ;
        SET t1 = DATE_ADD(t1, INTERVAL 3 MINUTE);
      END WHILE;
    END;
    
    
    CALL myProc(now(), ADDDATE(NOW(), INTERVAL 15 MINUTE));
    

    http://sqlfiddle.com/#!2/5672e/9

    Or change your line:

    SET StartTS  = StartTS  + INTERVAL 3 MINUTE;
    

    to

    SET StartTS  = ADDDATE(StartTS, INTERVAL 3 MINUTE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to insert the output of multiple calculations into my text document:
I would like to insert a new DataGridViewRow into my DataGridView at a specific
I have created a test table in MySQL and would like to insert 10
I have a path in a string, C:\temp\mybackup.zip I would like insert a timestamp
Right now I have this code: $mysqldate = date(time()); mysql_query(INSERT INTO permissions (date) VALUES
I am attempting to insert a copy of a row from one table into
I would like to insert the current Subversion revision number (as reported by svnversion
I would like to insert dates in an emacs buffer like I do in
I would like to insert notes on the fixes to be done in specific
In a part of my website I would like to insert some images and

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.