Mysql Get Current Date, Week, Month, YEAR Data

Mysql Get Current Date, Week, Month, YEAR Data

Mysql get current date, week, month, year data; Through this 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.

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

You can use the following MySQL queries to get data of current date, week, month, year; as shown below:

  • 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

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

AuthorAdmin

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, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

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

  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 *