0

I am wondering if anyone can suggest solutions for adding together datetimes in mysql?

I have a scheduler datetime, and want to add another datetime which specifies a period like '2012-03-23 10:00:00' + '0000-00-00 01:01:01' Should of course produce '2012-03-23 11:01:01'.

MySQL doesn't seem to like doing this with any of the DATE_ADD/ADDDATE variants.

Hope there are some solutions for this.

1
  • What is the datatype of the second "datetime"? '0000-00-00 01:01:01' is not a datetime that can be stored in the database since month 0/day 0 does not exist. Commented Mar 23, 2012 at 11:21

2 Answers 2

1

Visit mysql addDate

The syntax is:

mysql> SELECT ADDTIME('2007-12-31 23:59:59.999999', '1 1:1:1.000002');

   -> '2008-01-02 01:01:01.000001'

mysql> SELECT ADDTIME('01:00:00.999999', '02:00:00.999998');

   -> '03:00:01.999997'
Sign up to request clarification or add additional context in comments.

Comments

0

Try

DATE_ADD(DATE_ADD(DATE_ADD(NOW(), INTERVAL 1 HOUR), INTERVAL 1 MINUTE), INTERVAL 1 SECOND)

Works for me...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.