{"id":8377,"date":"2021-02-02T05:19:00","date_gmt":"2021-02-02T05:19:00","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=8377"},"modified":"2026-02-11T06:09:09","modified_gmt":"2026-02-11T06:09:09","slug":"how-to-get-data-for-every-hour-in-mysql","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/","title":{"rendered":"How to Get Data For Every Hour in MySQL"},"content":{"rendered":"\n<p>MySQL is a popular database system used by many organizations and teams all around the world. It provides excellent data analysis and reporting capabilities. Often database programmers and data analysts need to retrieve data for every hour in MySQL database. This is especially required if you have a high traffic website that generates a lot of data every hour. In such cases, your team will need to analyze data every hour and you will need to get hourly data, or fetch records for every hour in MySQL. In this article, we will look at how to get data for every hour in MySQL.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#How_to_Get_Data_For_Every_Hour_in_MySQL\" >How to Get Data For Every Hour in MySQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#Group_data_By_Hour_0-23\" >Group data By Hour (0-23)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#Filter_Data_Before_Grouping\" >Filter Data Before Grouping<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#Group_Data_by_Date_Hour\" >Group Data by Date &amp; Hour<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#Group_Data_By_AMPM\" >Group Data By AM\/PM<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#Group_Data_in_Different_Timezones\" >Group Data in Different Timezones<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Get_Data_For_Every_Hour_in_MySQL\"><\/span>How to Get Data For Every Hour in MySQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We will basically retrieve the hour value from datetime or time column and then use it in GROUP BY clause to group data by hour. You can use the same approach for getting data by other units of time such as day, minute, etc. MySQL provides DATE(), MINUTE() functions to get date and minute respectively.<\/p>\n\n\n\n<p>We will need to use HOUR() function to get the hour value from a datetime column. HOUR function retrieves hour number from a given date\/time\/datetime value, which can be provided as a literal string or column name. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT HOUR(column_name) AS hour FROM table_name;<\/pre>\n\n\n\n<p>Let us say you have the following table <em>sales(id, order_date, amount)<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; create table sales(id int, \n           order_date datetime, \n           amount int);\n\n mysql&gt; insert into sales(id, order_date, amount)\n      values(1, '2021-02-02 08:15:00',250),\n      (2, '2021-02-02 08:30:00',200),\n      (3, '2021-02-02 08:55:00',150),\n      (4, '2021-02-02 09:15:00',125),\n      (5, '2021-02-02 09:30:00',250),\n      (6, '2021-02-02 09:45:00',200),\n      (7, '2021-02-02 10:15:00',180),\n      (8, '2021-02-02 10:30:00',125),\n      (9, '2021-02-02 10:45:00',200),\n      (10, '2021-02-02 11:15:00',250),\n      (11, '2021-02-02 11:30:00',150),\n      (12, '2021-02-02 11:45:00',200);\n\n mysql&gt; select * from sales;\n +------+---------------------+--------+\n | id   | order_date          | amount |\n +------+---------------------+--------+\n |    1 | 2021-02-02 08:15:00 |    250 |\n |    2 | 2021-02-02 08:30:00 |    200 |\n |    3 | 2021-02-02 08:55:00 |    150 |\n |    4 | 2021-02-02 09:15:00 |    125 |\n |    5 | 2021-02-02 09:30:00 |    250 |\n |    6 | 2021-02-02 09:45:00 |    200 |\n |    7 | 2021-02-02 10:15:00 |    180 |\n |    8 | 2021-02-02 10:30:00 |    125 |\n |    9 | 2021-02-02 10:45:00 |    200 |\n |   10 | 2021-02-02 11:15:00 |    250 |\n |   11 | 2021-02-02 11:30:00 |    150 |\n |   12 | 2021-02-02 11:45:00 |    200 |\n +------+---------------------+--------+<\/pre>\n\n\n\n<p>We will look at several important use cases to aggregate hourly data in MySQL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Group_data_By_Hour_0-23\"><\/span>Group data By Hour (0-23)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is the simplest case where we just want to group our table&#8217;s data for every hour. Here is the SQL query to get data for every hour in MySQL. We use HOUR() function with GROUP BY clause. Please note, you need to use the same HOUR() function and column name in both SELECT as well as GROUP BY parts of your SQL query. This query will group data for each hour of day (0-23).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select hour(order_date),sum(amount)\n       from sales\n       group by hour(order_date);\n +------------------+-------------+\n | hour(order_date) | sum(amount) |\n +------------------+-------------+\n |                8 |         600 |\n |                9 |         575 |\n |               10 |         505 |\n |               11 |         600 |\n +------------------+-------------+<\/pre>\n\n\n\n<p>In the above query, we simply group by <em>order_date<\/em> using HOUR function and aggregate <em>amount<\/em> column using SUM function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Filter_Data_Before_Grouping\"><\/span>Filter Data Before Grouping<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can filter the input data used for aggregation by using WHERE clause as shown below. Here is an example to use data between dates Feb 1, 2021 and March 1, 2021.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select hour(order_date),sum(amount)<br>       from sales<br><strong>       where order_date between '2021-02-01' and '2021-03-01'<\/strong><br>       group by hour(order_date);<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Group_Data_by_Date_Hour\"><\/span>Group Data by Date &amp; Hour<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the above example, all data is grouped within hours 0-23 irrespective of the dates. In order to avoid mixing data pertaining to different dates, you may need to aggregate it by date and hour. You can do this by using date() and hour() functions as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ELECT DATE(column_name) AS date, HOUR(column_name) AS hour, COUNT(*)<br>FROM table_name<br>GROUP BY DATE(column_name), HOUR(column_name);<\/pre>\n\n\n\n<p>Here is an example to aggregate sales data by date and hour.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select date(order_date),hour(order_date),sum(amount)<br>       from sales<br>       group by date(order_date),hour(order_date);<\/pre>\n\n\n\n<p>Please note, in this case, you need to call date() and hour() functions in both SELECT as well as GROUP BY clauses.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Group_Data_By_AMPM\"><\/span>Group Data By AM\/PM<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to display hour values using AM\/PM notation such as 8AM, 9AM , etc, then you need to use date_format function that allows you to change the format of a given date\/time\/datetime value, which can be provided as a literal string or column name. Here is the syntax of date_format() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">DATE_FORMAT(date, format)<\/pre>\n\n\n\n<p>You need to provide the date value as literal string or column name. The format specifiers can be one of <a href=\"https:\/\/www.w3schools.com\/sql\/func_mysql_date_format.asp\" target=\"_blank\" rel=\"noreferrer noopener\">these<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select date_format(order_date,'%H %p') as hour,\n        sum(amount) as total_sales\n        from sales\n        group by date_format(order_date,'%H %p');\n +-------+-------------+\n | hour  | total_sales |\n +-------+-------------+\n | 08 AM |         600 |\n | 09 AM |         575 |\n | 10 AM |         505 |\n | 11 AM |         600 |\n +-------+-------------+<\/pre>\n\n\n\n<p>Please note, in this query also, you need to mention the same date_format() function in both SELECT as well as GROUP clauses of your SQL query. date_format() function is very useful to round timestamp values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Group_Data_in_Different_Timezones\"><\/span>Group Data in Different Timezones<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If your data contains datetime values for different time zones, then you will need to convert them all into the same time zone such as UTC (Coordinated Time) before grouping it. You can easily convert datetime to UTC in MySQL using convert_tz() function. Here is an example to change time zone of column before grouping it by the hour.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select hour(CONVERT_TZ(order_date, '+00:00', your_timezone)),sum(amount)<br>       from sales<br>       group by hour(CONVERT_TZ(order_date, '+00:00', your_timezone));<\/pre>\n\n\n\n<p>In this article, we have learnt how to get single count in MySQL. If you need to get <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-multiple-counts-in-single-query\/\">multiple counts in a single query<\/a>, you can refer to the steps <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-multiple-counts-in-single-query\/\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Many organizations needs to report MySQL data by date and hour. In this article, we have learnt several simple ways to quickly aggregate data by hour, date and hour, as AM\/PM. There are broadly two ways to aggregate data by time intervals &#8211; using built time functions such as HOUR(), DATE(), etc. and using date_format() function. You can use either of these methods. We recommend using date_format() function because it is super versatile and supports a vast range of time series aggregations. Please remember, if your data is involves different time zones, then it is advisable to convert it into a consistent time zone before you aggregate it.<\/p>\n\n\n\n<p>Need a reporting tool for MySQL?&nbsp;<a href=\"http:\/\/ubiq.co\/\">Ubiq<\/a>&nbsp;makes it easy to visualize data in minutes, and monitor in real-time dashboards.&nbsp;<a href=\"http:\/\/ubiq.co\/accounts\/register\">Try it<\/a>&nbsp;Today!<\/p>\n\n\n\n<p>Also read:<br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-last-1-hour-data-in-mysql\/\">How to Get Last 1 hour data in MySQL<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-show-rows-not-present-in-another-table-in-mysql\/\">How to Show Rows Not Present in MySQL Table<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-current-week-data-in-mysql\/\">How to Get Current Week Data in MySQL<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to get data for every hour, or retrieve hourly data in MySQL. Here is how to get data for every hour in MySQL.<\/p>\n","protected":false},"author":1,"featured_media":8379,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324],"tags":[437],"class_list":["post-8377","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-hourly-data"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Get Data For Every Hour in MySQL - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to get data for every hour, or retrieve hourly data in MySQL. Here is how to get data for every hour in MySQL.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Get Data For Every Hour in MySQL - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to get data for every hour, or retrieve hourly data in MySQL. Here is how to get data for every hour in MySQL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-02T05:19:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-11T06:09:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/02\/get-hourly-data-mysql.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"730\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Get Data For Every Hour in MySQL\",\"datePublished\":\"2021-02-02T05:19:00+00:00\",\"dateModified\":\"2026-02-11T06:09:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/\"},\"wordCount\":848,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1\",\"keywords\":[\"hourly data\"],\"articleSection\":[\"MySQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/\",\"name\":\"How to Get Data For Every Hour in MySQL - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1\",\"datePublished\":\"2021-02-02T05:19:00+00:00\",\"dateModified\":\"2026-02-11T06:09:09+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to get data for every hour, or retrieve hourly data in MySQL. Here is how to get data for every hour in MySQL.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1\",\"width\":730,\"height\":400,\"caption\":\"get hourly data in mysql\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-data-for-every-hour-in-mysql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Get Data For Every Hour in MySQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Get Data For Every Hour in MySQL - Ubiq BI","description":"Sometimes you may need to get data for every hour, or retrieve hourly data in MySQL. Here is how to get data for every hour in MySQL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/","og_locale":"en_US","og_type":"article","og_title":"How to Get Data For Every Hour in MySQL - Ubiq BI","og_description":"Sometimes you may need to get data for every hour, or retrieve hourly data in MySQL. Here is how to get data for every hour in MySQL.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2021-02-02T05:19:00+00:00","article_modified_time":"2026-02-11T06:09:09+00:00","og_image":[{"width":730,"height":400,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/02\/get-hourly-data-mysql.webp","type":"image\/webp"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Get Data For Every Hour in MySQL","datePublished":"2021-02-02T05:19:00+00:00","dateModified":"2026-02-11T06:09:09+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/"},"wordCount":848,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/02\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1","keywords":["hourly data"],"articleSection":["MySQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/","name":"How to Get Data For Every Hour in MySQL - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/02\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1","datePublished":"2021-02-02T05:19:00+00:00","dateModified":"2026-02-11T06:09:09+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to get data for every hour, or retrieve hourly data in MySQL. Here is how to get data for every hour in MySQL.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/02\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/02\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1","width":730,"height":400,"caption":"get hourly data in mysql"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-data-for-every-hour-in-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Get Data For Every Hour in MySQL"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/02\/get-hourly-data-mysql.webp?fit=730%2C400&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-2b7","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=8377"}],"version-history":[{"count":4,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8377\/revisions"}],"predecessor-version":[{"id":10576,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8377\/revisions\/10576"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/8379"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=8377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=8377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=8377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}