{"id":2703,"date":"2018-06-25T02:08:17","date_gmt":"2018-06-25T09:08:17","guid":{"rendered":"https:\/\/database.guide\/?p=2703"},"modified":"2021-01-28T14:11:20","modified_gmt":"2021-01-28T04:11:20","slug":"dayname-examples-mysql","status":"publish","type":"post","link":"https:\/\/database.guide\/dayname-examples-mysql\/","title":{"rendered":"DAYNAME() Examples &#8211; MySQL"},"content":{"rendered":"<p>You can use the <code>DAYNAME()<\/code> function in <a href=\"https:\/\/database.guide\/what-is-mysql\/\">MySQL<\/a> to return the weekday name from a date.<\/p>\n<p>By &#8220;weekday name&#8221;, I mean a value like Monday or Sunday. For example, if you provide a date of <em>2018-01-07<\/em>, the <code>DAYNAME()<\/code> function will return <em>Sunday<\/em>.<\/p>\n<p><!--more--><\/p>\n<h2>Syntax<\/h2>\n<p>The syntax goes like this:<\/p>\n<pre>DAYNAME(date)\r\n<\/pre>\n<p>Where <code>date<\/code> is the date value that you want the weekday name returned from.<\/p>\n<h2>Example<\/h2>\n<p>Here&#8217;s an example to demonstrate.<\/p>\n<pre>SELECT DAYNAME('2021-03-16') AS 'Result';\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+---------+\r\n| Result  |\r\n+---------+\r\n| Tuesday |\r\n+---------+\r\n<\/pre>\n<h2>A Database Example<\/h2>\n<p>Here&#8217;s an example of extracting the weekday name from a column when running a query against a database.<\/p>\n<pre>USE sakila;\r\nSELECT\r\n  payment_date AS 'Date\/Time',\r\n  DAYNAME(payment_date) AS 'Weekday Name'\r\nFROM payment\r\nWHERE payment_id = 1;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+---------------------+--------------+\r\n| Date\/Time           | Weekday Name |\r\n+---------------------+--------------+\r\n| 2005-05-25 11:30:37 | Wednesday    |\r\n+---------------------+--------------+\r\n<\/pre>\n<h2>Current Date\/Time<\/h2>\n<p>Here&#8217;s an example of extracting the weekday name from the current date and time (which is returned using the <a href=\"https:\/\/database.guide\/now-examples-mysql\/\"><code>NOW()<\/code><\/a> function).<\/p>\n<pre>SELECT \r\n    NOW(),\r\n    DAYNAME(NOW());\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+---------------------+----------------+\r\n| NOW()               | DAYNAME(NOW()) |\r\n+---------------------+----------------+\r\n| 2018-06-25 19:05:41 | Monday         |\r\n+---------------------+----------------+\r\n<\/pre>\n<p>Another way to do this is to use the <a href=\"https:\/\/database.guide\/curdate-examples-mysql\/\"><code>CURDATE()<\/code><\/a> function, which returns only the date (but not the time).<\/p>\n<pre>SELECT \r\n    CURDATE(),\r\n    DAYNAME(CURDATE());    \r\n<\/pre>\n<p>Result:<\/p>\n<pre>+------------+--------------------+\r\n| CURDATE()  | DAYNAME(CURDATE()) |\r\n+------------+--------------------+\r\n| 2018-06-25 | Monday             |\r\n+------------+--------------------+\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can use the DAYNAME() function in MySQL to return the weekday name from a date. By &#8220;weekday name&#8221;, I mean a value like Monday or Sunday. For example, if you provide a date of 2018-01-07, the DAYNAME() function will return Sunday.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[68,115,93],"class_list":["post-2703","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-date-functions","tag-dates","tag-functions"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=2703"}],"version-history":[{"count":4,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2703\/revisions"}],"predecessor-version":[{"id":2707,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2703\/revisions\/2707"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=2703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=2703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=2703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}