Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating DATETIME from DATE and TIME

Tags:

datetime

mysql

Is there way in MySQL to create DATETIME from a given attribute of type DATE and a given attribute of type TIME?

like image 768
gregor Avatar asked Aug 23 '09 13:08

gregor


People also ask

How do I convert a date to datetime?

You can use the datetime module's combine method to combine a date and a time to create a datetime object. If you have a date object and not a time object, you can initialize the time object to minimum using the datetime object(minimum time means midnight).

How do I convert a timestamp to a datetime?

Import the “datetime” file to start timestamp conversion into a date. Create an object and initialize the value of the timestamp. Use the ” fromtimestamp ()” method to place either data or object. Print the date after conversion of the timestamp.


1 Answers

Copied from the MySQL Documentation:

TIMESTAMP(expr), TIMESTAMP(expr1,expr2)

With a single argument, this function returns the date or datetime expression expr as a datetime value. With two arguments, it adds the time expression expr2 to the date or datetime expression expr1 and returns the result as a datetime value.

mysql> SELECT TIMESTAMP('2003-12-31');     -> '2003-12-31 00:00:00' mysql> SELECT TIMESTAMP('2003-12-31 12:00:00','12:00:00');     -> '2004-01-01 00:00:00' 
like image 183
johnson Avatar answered Oct 02 '22 09:10

johnson