- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create DATETIME from DATE and TIME in MySQL?
You can create DATETIME from DATE and TIME with the help of ADDTIME() function in MySQL. The syntax is as follows −
SELECT ADDTIME(CONVERT(yourDateColumnName,datetime),yourTimeColumnName) as anyVariableName from yourTableName;
To understand the above concept, let us create a table. The query to create a table is as follows −
mysql> create table DateTime −> ( −> DueDate date, −> DueTime time −> ); Query OK, 0 rows affected (1.19 sec)
Now you can insert date and time separately. The query to insert is as follows −
mysql> insert into DateTime values(curdate(),now()); Query OK, 1 row affected (0.08 sec)
Display all records from the table with the help of select statement −
mysql> select *from DateTime;
The following is the output −
+------------+----------+ | DueDate | DueTime | +------------+----------+ | 2018-12-11 | 09:59:07 | +------------+----------+ 1 row in set (0.00 sec)
Now you can implement the syntax we discussed in the beginning to create a datetime from date and time. The query is as follows −
mysql> select addtime(convert(DueDate,datetime),DueTime) as DATETimeDemo from DateTime;
The following is the output displaying datetime created from date and time −
+---------------------+ | DATETimeDemo | +---------------------+ | 2018-12-11 09:59:07 | +---------------------+ 1 row in set (0.00 sec)
- How to part DATE and TIME from DATETIME in MySQL?
- MySQL strip time component from datetime?
- Add DATE and TIME fields to get DATETIME field in MySQL?
- How to convert JS date time to MySQL datetime?
- Get only the date from datetime in MySQL?
- How to combine date and time from different MySQL columns to compare with the entire DateTime?
- MySQL Query to convert from datetime to date?
- How to split the datetime column into date and time and compare individually in MySQL?
- Compare DATE string with string from MySQL DATETIME field?
- How to select only MySQL date from datetime column?
- How to compare DateTime Column with only Date not time in MySQL?
- Write a program to separate date and time from the datetime column in Python Pandas
- Changing data type from date to date/time in MySQL?
- Extracting only date from datetime field in MySQL and assigning it to PHP variable?
- Insert current date in datetime format MySQL?