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 6375231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:35:21+00:00 2026-05-25T01:35:21+00:00

I am making a timer function that runs in MySQL, and it sets start_time

  • 0

I am making a timer function that runs in MySQL, and it sets start_time with MySQL CURRENT_TIMESTAMP when they start the timer.

When they stop the timer, I calculate in the SQL the time difference, and add it on to time, and set start_time to 0 again.

UPDATE `time`
   SET `time` = time + (UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(start_time)),
       `start_time` = '0000-00-00 00:00:00' 
 WHERE `id` =  '1'

When I stop the timer, instead of using the start_time in the query, it sets it to 0000-00-00 00:00:00 first, so my time is actually (time + (UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP('0000-00-00 00:00:00'))), which is not the correct value.

CREATE TABLE IF NOT EXISTS `time` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `time` double NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `start_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

How can I fix this?

  • 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-05-25T01:35:21+00:00Added an answer on May 25, 2026 at 1:35 am

    Why not do it in two separate updates?

    UPDATE `time`
       SET `time` = (time + (UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(start_time)))
     WHERE `id` =  '1';
    
    UPDATE `time`
    `start_time` = '0000-00-00 00:00:00' 
    WHERE `id` =  '1'
    

    Look at your schema. The default value is set to that and the update statement is using the current value of it. Are you changing the value of start timer before hand? Try adding a select before your update to see what the value of start_time is.

    I just tried this..

    update time
    set start_time = ‘2011-08-28 17:02:47’
    where id = 1;

    UPDATE time
    SET time = (time + (UNIX_TIMESTAMP(CURRENT_TIMESTAMP) – UNIX_TIMESTAMP(start_time))), start_time = ‘0000-00-00 00:00:00’
    WHERE id = ‘1’;

    and id = 1 got a correct number in time. Check to make sure start_time and time have good values.

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

Sidebar

Related Questions

I have a function that sets a timer, and calls itself back upon expiration
I am looking for some (preferably) online tutorials on making controls with 'Rich design-time
I have a JavaScript slideshow that pre-loads images out of a MySQL database and
I'm trying to edit my timer so that every 25 times repaint() is called
I am trying to create a function with a variant record-type parameter that allows
This is beyond both making sense and my control. That being said here is
I have a function that changes the hash in the url and inserts/removes a
I have a function that calls jQuery's pulse function. I use it on a
I'm trying to create a function that i can use over and over. I
I have a few panels that I slide horizontally using the animate function that

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.