0

I have tbl1 which has field date and time.Suppose there's another table tbl2 with field date_time.Now,I want to take data from date & time field of tbl1,combine them and insert to date_time field of tbl2,in Y-m-d H:i:s format or which ever format possible.Please some one help,inserting from one table to another isn't a problem but combining value of two field then inserting to another table is making me headache?

1
  • What is the relation between these tables? Commented Aug 12, 2015 at 6:45

2 Answers 2

1

You should concatenate the date and time field from tbl1.

Something like this:

INSERT INTO tbl2 (datetime_field) 
VALUES (SELECT CONCAT(date_filed, ' ', time_field) 
        FROM tbl1 WHERE pk_field = your_condition);

Notice: The sub-select must return only one result!

Sign up to request clarification or add additional context in comments.

Comments

1
  INSERT INTO tbl2 (date_time)  
  SELECT CONCAT(`date`, ' ', `time`)
  FROM tbl1
  WHERE your_condition

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.