Mysql Get Data Of Current Date, Week, Month, YEAR

Mysql Get Data Of Current Date, Week, Month, YEAR

In this MySQL tutorial – we would love to share with you how to get current date, current week, current, month, current year data using MySQL queries.

We will also take few more examples of mysql current date/day, week, month, year, e.g. Day/Date Wise, Current Week Wise Data, Get Month Wise Current Year Data, Day Wise Current Month Data, Year Wise Date.

When we create a bar charts, line charts, pie charts, or analytics listings that time, we need to show data daily basis, weekly basis, monthly basis, yearly basis. Here you will learn how to fetch daily basis records, weekly basis record, monthly basis record etc from mysql database tables.

For example, If you are working with any ecommerce application. So you need to show daily basis orders profit or loss analytics, weekly basis profit or loss analytics, monthly basis profit or loss analytics etc.

Table Of Content

  • Current Date Record
  • Current WEEK Record
  • Get Day Wise Current Week Data
  • Current Month Record
  • Get Month Wise Current Year Data
  • Day Wise Current Month Data
  • Current Year Record
  • Year Wise Date

Current Date Record

If you want to fetch current date record from database tables. Use the below MySQL Query for fetching the current date records.

SELECT name, created_at
FROM employees 
WHERE DATE(created_at) = DATE(NOW()) ORDER BY `id` DESC
Current Date Record mysql

Current WEEK Record

Using the below MySQL query for fetching the current week records from the mysql database table.

SELECT name, created_at as create_date
FROM employees 
WHERE YEARWEEK(created_at) = YEARWEEK(NOW()) ORDER BY `created_at` DESC
Current WEEK Record Mysql

Get Day Wise Current Week Data

Get day wise current week data from mysql database table. Use the below mysql query for that.

SELECT DATE(created_at) as Date, DAYNAME(created_at) as 'Day Name', COUNT(id) as Count  
FROM employees
WHERE date(created_at) > DATE_SUB(NOW(), INTERVAL 1 WEEK) AND MONTH(created_at) = MONTH(CURDATE()) AND YEAR(created_at) = YEAR(CURDATE())
GROUP BY DAYNAME(created_at) ORDER BY (created_at)
Get Day Wise Current Week Data MYSQL

Current Month Record

MySQL get current month records from DateTime. Use the below query that find the current month records from the mysql database table.

SELECT name, created_at as create_date
FROM employees 
WHERE MONTH(created_at) = MONTH(NOW()) ORDER BY `id` DESC
Current Month Record mysql

Get Month Wise Current Year Data

If you want to get current year data month wise from database table. Use the below mysql query for fetch the records from month wise of current year.

SELECT COUNT(id) as Count,MONTHNAME(created_at) as 'Month Name'
FROM employees WHERE YEAR(created_at) = YEAR(CURDATE())
GROUP BY YEAR(created_at),MONTH(created_at)
Get Month Wise Current Year Data mysql

Day Wise Current Month Data

Get day wise current month records from the mysql database table. Use the below MySQL query for fetch the current month records from day wise.

SELECT COUNT(id) as Count, DAY(created_at) as 'Day', DAYNAME(created_at) as 'Day Name'
FROM employees
WHERE MONTH(created_at) = MONTH(CURDATE())
AND YEAR(created_at) = YEAR(CURDATE())
GROUP BY DAY(created_at)
Day Wise Current Month Data mysql

Current Year Record

You want to fetch the current year records from the mysql database table. Use the below to get the current year records from database table.

SELECT name, YEAR(CURDATE())
FROM employees 
WHERE YEAR(created_at) = YEAR(NOW()) ORDER BY `id` DESC
Current Year Record MYSQL

Year Wise Data

You want to fetch year wise data. Use the below query for get year wise data from mysql database table.

SELECT COUNT(id) as Count,YEAR(created_at) as Year
FROM employees
GROUP BY YEAR(created_at)
Year Wise Data

Conclusion

Here, You have learned how to fetch data day, date, week, month, year wise with examples.

Recommended MySQL Tutorial

  1. WEEKOFYEAR() Function Examples – MySQL
  2. DAYOFMONTH() MySQL Function – MySQL Tutorial
  3. DAY() MySQL Function – MySQL
  4. MySQL DATEDIFF: Calculate Days Between Two Dates
  5. WEEKDAY() Function Examples – MySQL
  6. LAST_DAY MySQL Function Examples
  7. MySQL – DAYOFWEEK() Function Examples
  8. DAYOFYEAR() Function Examples – MySQL
  9. MySQL YEARWEEK() Function Examples – MySQL
  10. MySQL weekday function with example
  11. MySQL CURRENT TIMESTAMP Function Examples
  12. Query For Get Data Of Last Day, Week, Month, YEAR – Mysql
  13. LAST_DAY MySQL Function Examples
  14. MySQL CURRENT TIMESTAMP Function Examples
  15. Get month name from date in mysql
  16. mysql get first day of the current month
  17. mysql last day of previous month
  18. Get month number from month name in mysql
  19. mysql get day of week number from date
  20. Mysql Get Data Of Current Date, Week, Month, YEAR

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorTuts Make

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

One reply to Mysql Get Data Of Current Date, Week, Month, YEAR

  1. Thanks Sir Nice Tutorial,

    This Post Solve my All SQL data retrieve Problems

    THANKS.

Leave a Reply

Your email address will not be published. Required fields are marked *