Practical 19 - MySQL - Date Time Functions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Practical 19

Date & Time Functions


Introduction -
now() -
curdate() -
date() -
month() -
day() -
weekday() -
dayname() -
dayofyear() -

mysql> select now();

+---------------------+

| now() |

+---------------------+

| 2021-01-27 11:55:16 |

+---------------------+

1 row in set (0.00 sec)

mysql> select curdate();

+------------+

| curdate() |

+------------+

| 2021-01-27 |

+------------+

1 row in set (0.00 sec)


mysql> select date('2021-01-27 11:54:56');

+-----------------------------+

| date('2021-01-27 11:54:56') |

+-----------------------------+

| 2021-01-27 |

+-----------------------------+

1 row in set (0.00 sec)

mysql> select month('2021-07-02');

+---------------------+

| month('2021-07-02') |

+---------------------+

| 7 |

+---------------------+

1 row in set (0.00 sec)

mysql> select day('2021-07-02');

+-------------------+

| day('2021-07-02') |

+-------------------+

| 2 |

+-------------------+

1 row in set (0.00 sec)

mysql> select weekday('2021-07-02');

+-----------------------+

| weekday('2021-07-02') |

+-----------------------+

| 4 |
+-----------------------+

1 row in set (0.00 sec)

mysql> select weekday('2021-01-27');

+-----------------------+

| weekday('2021-01-27') |

+-----------------------+

| 2 |

+-----------------------+

1 row in set (0.00 sec)

mysql> select dayname('2021-01-27');

+-----------------------+

| dayname('2021-01-27') |

+-----------------------+

| Wednesday |

+-----------------------+

1 row in set (0.00 sec)

mysql> select dayname('2021-02-27');

+-----------------------+

| dayname('2021-02-27') |

+-----------------------+

| Saturday |

+-----------------------+

1 row in set (0.00 sec)

mysql> select dayofyear('2021-02-27');

+-------------------------+

| dayofyear('2021-02-27') |
+-------------------------+

| 58 |

+-------------------------+

1 row in set (0.00 sec)

You might also like