Mysql Get Current Date, Week, Month, YEAR Data

Mysql get current date, week, month, year data; Through this tutorial, i am going to show you how to get current date, current week, current, month, current year data in MySQL.

How to Get Data Of Current Date, Week, Month, YEAR in MySQL

Use the following MySQL queries to get data of current date, week, month, year; as follows:

  • 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

To get current date record from database tables; so you can use the following 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 WEEK Record

To get current week record; so you can use the following 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

Get Day Wise Current Week Data

To get day wise current week data from mysql database table. So, you can use the following MySQL query; as follows:

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)

Current Month Record

To get current month records from DateTime; so you can use the following query to find the current month records from the mysql database table; as follows:

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

Get Month Wise Current Year Data

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; as follows:

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)

Day Wise Current Month Data

To fetch day wise current month records from the mysql database table. Use the below MySQL query for fetch the current month records from day wise; as follows:

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)

Current Year Record

To get the current year records from the mysql database table. So, you can use the following MySQL query 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

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)

Conclusion

Mysql Get Current Date, Week, Month, YEAR Data tutorial, You have learned how to fetch data day, date, week, month, year-wise with examples.

One Comment

  1. Hemant Kumar said:

    Thanks Sir Nice Tutorial,

    This Post Solve my All SQL data retrieve Problems

    THANKS.

    January 8, 2020
    Reply

Leave a Reply

Your email address will not be published.