Tutorialspoint

1 Answer
Ankith Reddy

To get the day name from timestamp, use dayname() function −

select dayname(yourColumnName) from yourTableName;
   Let us first create a table :
   mysql> create table DemoTable
   (
   LoginDate timestamp
   );
Query OK, 0 rows affected (0.52 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('2019-06-01');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable values('2019-06-02');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values('2019-06-03');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values('2019-06-04');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values('2018-06-21');
Query OK, 1 row affected (0.09 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+-----------------------+
| LoginDate             |
+-----------------------+
| 2019-06-01 00 :00 :00 |
| 2019-06-02 00 :00 :00 |
| 2019-06-03 00 :00 :00 |
| 2019-06-04 00 :00 :00 |
| 2018-06-21 00 :00 :00 |
+-----------------------+
5 rows in set (0.00 sec)

Following is the query to get day name from timestamp in MySQL −

mysql> select dayname(LoginDate) from DemoTable;

Output

+--------------------+
| dayname(LoginDate) |
+--------------------+
| Saturday           |
| Sunday             |
| Monday             |
| Tuesday            |
| Thursday           |
+--------------------+
5 rows in set (0.00 sec)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.