Mysql Get Data Of Current Date, Week, Month, YEAR
Mysql 02-Jun-2021

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.