Arrow

SQL Date Time Data Type

AuthorHariom Prajapati

Pubish Date03 Jul 2022

categoryMySql

My SQL comes with the following data types for storing a date or a date/time value in the database.

  • DATE : YYY-MM-DD
  • TIME : HH:MI:SS
  • DATETIME : YYYY-MM_DD HH:MML:SS

 

Date time data type with pre-defined functions

  • CURDATE ( ) : Give current date ( YYYY-MM-DD )
  • CURTIME ( ) : Give current time ( HH:MI:SS )
  • NOW ( ) : Give both current date and current time ( YYYY-MM-DD HH:MML:SS )

 NOTE : This all the above data types are used in the table.

 

Syntax -

The syntax is the same as creating a table but where we declare date & time type like varchar, int etc. there we need to write the above data type.

when we insert data into this data type we must follow the above formate of date, time and DateTime.

 

NOTE: Inserted data into this data type must be inside ( ' ' ).

sql date time data type

sql date time data type