Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:39:52+00:00 2026-06-17T06:39:52+00:00

For example MySQL NOW() returns 2013-01-09 12:20:06 , so i need to count all

  • 0

For example MySQL NOW() returns 2013-01-09 12:20:06, so i need to count all rows as specified below.

Current:

  • Hour: from 2013-01-09 12:00:00 till NOW()
  • Day: from 2013-01-08 00:00:00 till NOW()
  • Month: from 2013-01-01 00:00:00 till NOW()

Previous

  • Hour: 2013-01-09 11:00:00 – 2013-01-09 12:00:00
  • Day: 2013-01-08 00:00:00 – 2013-01-08 23:59:59
  • Month: 2012-12-01 00:00:00 – 2013-01-01 00:00:00

I tried something like:

WHERE
    `date` >= DATE_FORMAT(NOW(), '%Y-%m-%d %h:00:00')
AND `date` >= DATE_SUB(
    DATE_FORMAT(NOW(), '%Y-%m-%d %h:00:00'),
    INTERVAL 10 MONTH
)

But may be there is more convenient way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:39:54+00:00Added an answer on June 17, 2026 at 6:39 am

    Try this:

    For CURRENT:

    SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:00:00');
    SELECT DATE_FORMAT(NOW(), '%Y-%m-%d 00:00:00');
    SELECT DATE_FORMAT(NOW(), '%Y-%m-01 00:00:00');
    

    For PREVIOUS:

    SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:00:00'), DATE_SUB(DATE_FORMAT(NOW(), '%Y-%m-%d %H:00:00'), INTERVAL 1 HOUR);
    SELECT DATE_FORMAT(NOW(), '%Y-%m-%d 00:00:00'), DATE_SUB(DATE_FORMAT(NOW(), '%Y-%m-%d 00:00:00'), INTERVAL 1 DAY);
    SELECT DATE_FORMAT(NOW(), '%Y-%m-01 00:00:00'), DATE_SUB(DATE_FORMAT(NOW(), '%Y-%m-01 00:00:00'), INTERVAL 1 MONTH);
    

    Check this link SQL FIDDLE DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table t_points in mySql like example in below. Name Surname Point
From the mysql certification guide's example questions ... question Will the following SQL statement
Below is a very basic example of the trouble I am having. Now why
I want to retrieve a row from a MySQL database which returns a row,
Morning all! My MySQL query returns a PHP variable name which I'd like to
I'm finding it difficult learning how to formulate subqueries in MySQL For example, this
For example I have a mysql query that gets some data. Then runs another
Between Mysql and PostgreSQL,which is suite for very large scale of data..for example, millions
In the following example, MySQL fails to use to find a ref for the
In MySQL 5.0.67 can you specify a time delay on a trigger? For example,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.