Order by timestamp value : TimeStamp « Data Type « SQL / MySQL






Order by timestamp value

      
mysql>
mysql> CREATE TABLE temporal_val
    -> (
    ->  d       DATE,
    ->  dt      DATETIME,
    ->  t       TIME,
    ->  ts      TIMESTAMP
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO temporal_val (d, dt, t, ts)
    ->  VALUES
    ->          ('1970-01-01','1884-01-01 12:00:00','13:00:00','1980-01-01 02:00:00'),
    ->          ('1999-01-01','1860-01-01 12:00:00','19:00:00','2021-01-01 03:00:00'),
    ->          ('1981-01-01','1871-01-01 12:00:00','03:00:00','1975-01-01 04:00:00'),
    ->          ('1964-01-01','1899-01-01 12:00:00','01:00:00','1985-01-01 05:00:00')
    -> ;
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT * FROM temporal_val;
+------------+---------------------+----------+---------------------+
| d          | dt                  | t        | ts                  |
+------------+---------------------+----------+---------------------+
| 1970-01-01 | 1884-01-01 12:00:00 | 13:00:00 | 1980-01-01 02:00:00 |
| 1999-01-01 | 1860-01-01 12:00:00 | 19:00:00 | 2021-01-01 03:00:00 |
| 1981-01-01 | 1871-01-01 12:00:00 | 03:00:00 | 1975-01-01 04:00:00 |
| 1964-01-01 | 1899-01-01 12:00:00 | 01:00:00 | 1985-01-01 05:00:00 |
+------------+---------------------+----------+---------------------+
4 rows in set (0.00 sec)

mysql>
mysql> SELECT * FROM temporal_val ORDER BY ts;
+------------+---------------------+----------+---------------------+
| d          | dt                  | t        | ts                  |
+------------+---------------------+----------+---------------------+
| 1981-01-01 | 1871-01-01 12:00:00 | 03:00:00 | 1975-01-01 04:00:00 |
| 1970-01-01 | 1884-01-01 12:00:00 | 13:00:00 | 1980-01-01 02:00:00 |
| 1964-01-01 | 1899-01-01 12:00:00 | 01:00:00 | 1985-01-01 05:00:00 |
| 1999-01-01 | 1860-01-01 12:00:00 | 19:00:00 | 2021-01-01 03:00:00 |
+------------+---------------------+----------+---------------------+
4 rows in set (0.00 sec)

mysql>
mysql> drop table temporal_val;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
  








Related examples in the same category

1.TIMESTAMP as column type
2.timestamp type column default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
3.Table definition includes a YEAR column and a TIMESTAMP
4.dates and times in SQL commands must be given as character strings,
5.Recording a Row's Last Modification Time
6.Recording a Row's Creation Time
7.Performing Calculations with TIMESTAMP Values
8.Updates to tsdemo2 records that don't actually modify a column cause no change to TIMESTAMP values
9.Create a table in which timestamps can be stored.
10.The difference between the creation and modification times
11.Issuing an UPDATE statement that doesn't actually change the values in the val column doesn't update the TIMES
12.microseconds component is removed.