close[x]


MySQL

MySQL-Home MySQL-Environment setup MySQL- Workbench MySQL-Basic syntax MySQL-Operator MySQL-Data type MySQL-Comments MySQL-Create DB MySQL-Drop DB MySQL-Select DB MySQL-Create Table MySQL-Drop table MySQL-Truncate MySQL-Primary Key MySQL-Foreign Key MySQL-Null MySQL-Increment MySQL-Having MySQL-Top MySQL-Insert Statement MySQL-Select Statement MySQL-Alter Statement MySQL-Where MySQL-And & Or MySQL-Default values MySQL-Exists MySQL-Order by MySQL-View MySQL-Update Statement MySQL-Delete Statement MySQL-Like MySQL-Sort MySQL-Limit MySQL-Min MySQL-Max MySQL-Group MySQL-In MySQL-Between MySQL-Union MySQL-Count MySQL-Average MySQL-Sum MySQL-Date & Time MySQL-Import MySQL-Export MySQL-Index MySQL-Temporary MySQL-Join MySQL-Full Join MySQL-Inner Join MySQL-Left Join MySQL-Right Join MySQL-Store Procedure MySQL-Injection MySQL-PHP connection



learncodehere.com



MySQL - Dates

In MySQL, dates are complicated.

while working with database, the format of the date in table must be matched.

SQL SELECT DATE is used to retrieve a date from a database.

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

  • DATE - format YYYY-MM-DD
  • DATETIME - format: YYYY-MM-DD HH:MI:SS
  • SMALLDATETIME - format: YYYY-MM-DD HH:MI:SS
  • TIMESTAMP - format: a unique number
  • Now we want to select the records with a Date of "2008-11-11" from table .

    we use the following SELECT statement:

    
     SELECT * FROM 'table_name' WHERE Date='2008-11-11' 
    

    If the value of the date format is like 'YYYY-MM-DD' we can retrive a result.

    But if the value of the date format is other format like 'YYYY-MM-DD HH:MI:SS' we will get no result! This is because the query is looking only for dates with no time portion

    To keep your queries simple and easy to maintain, do not allow time components in your dates!