Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home MySQL MySQL Select Records Created In Last XXX Minutes

MySQL Select Records Created In Last XXX Minutes

This could be used to query records which were created in last 5 minutes, 30 minutes, 60 minutes, 120 minutes, etc with DATE_SUB(NOW(), INTERVAL 400 MINUTE)

For example, we have a MySQL log table has structure like this:

CREATE TABLE IF NOT EXISTS `code_used_logs` (
  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
  `code` VARCHAR(50) NOT NULL
  `created_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;

And we already have some records have been created. Now we will query which records have been created in last 600 minutes (10 hours).

SELECT id, code, created_date, DATE_SUB( NOW( ) , INTERVAL 600 MINUTE ) 
FROM mc_code_used_logs
WHERE created_date > DATE_SUB( NOW( ) , INTERVAL 600 MINUTE ) 
LIMIT 0 , 30

Output:

MySQL Select Records Created In Last XXX Minutes

MySQL Select Records Created In Last XXX Minutes

Sep 12, 2013 Hoan Huynh
PHP Check If A String Contains SomethingPHP Reset Array Indexes
You Might Also Like:
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • How To Track Website With Multiple Google Analytisc Accounts
  • Shell script backup all Mysql Databases in Linux
  • Mysql select current date, current time, current TIMESTAMP example
  • PHP Connect To MS SQL Server
  • Replace String With NText Or Text Data Type In MS SQL Server
  • Javascript Problem Set focus textbox on Firefox
  • PHP Load Facebook Albums And Save To MySQL Database
  • How To Tune And Optimize MySQL Performance With MySQLTuner
  • ASP.NET C# Export Data To CSV And Prompt Download
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at hoan@4rapiddev.com

5 years ago MySQLDATE_SUB, INTERVAL194
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
16,466 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
12,284 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
11,623 views
JQuery Allow only numeric characters or only alphabet characters in textbox
9,611 views
PHP Call Web Service WSDL Example
6,451 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Magento Fatal error: Unsupported operand types
  • Ionic bower the name contains uppercase letters
  • PHP Magento Get Manufacturer Name And ID From Magento Product ID
  • Know Simple Hacks To Systematize Media Library in WordPress
  • A handy guideline on adding custom menu item in WordPress admin
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (26)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (140)
EMAIL SUBSCRIPTION

Sign up for our newsletter to receive the latest news and event postings.

Recommended
  • CDN
  • Hosting
  • Premium Themes
  • VPS
2014 © 4 Rapid Development