[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2254
  • Last Modified:

Simple mysql statement, add x minutes to current time

Hello,
I have two fields

a time,
b time

I want to do an insert like this:

insert into table values (curtime(), curtime() + x minutes)

How do i do that?

Thanks!
0
scarab890
Asked:
scarab890
  • 3
  • 2
1 Solution
 
AlThePal7Commented:
You want something like this:

INSERT INTO test1 (a, b) VALUES (Curtime(), ADDTIME(Curtime(),"00:01:00"))

This will obviously add 1 minute to the current time for field b - just change the last string as required to add a different number of minutes.
0
 
scarab890Author Commented:
Hi,
Thanks for replying.

I had tried that before, but for some reason its not working, this is the table (exporting it):

CREATE TABLE costream_test2 (
  a time default NULL,
  b time default NULL
) TYPE=MyISAM;


This is what i ran:
INSERT INTO costream_test2
VALUES (Curtime( ) , ADDTIME(Curtime( ) , "00:01:00"))


But mysql is spitting out an error.

I am running version 3.23


Whats wrong?

Thanks!
0
 
AlThePal7Commented:
The ADDTIME() function was added in MySQL 4.1.1.   You could try

INSERT INTO costream_test2
VALUES (Curtime(), DATE_ADD(Now(), INTERVAL '1' MINUTE ))

The DATE_ADD function needs a DateTime value, so you have to use Now() instead of Curtime().
0
 
scarab890Author Commented:
I dont reall understand why date_add has to be used....but I do understand that your answer works perfectly and I appreciate it, I am increasing the points and accepting your answer as without it I would have to join the mysql list etc and wait for an answer!

Thanks!
0
 
AlThePal7Commented:
Your welcome, glad I could help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now