[SOLVED]DATETIME conditional expressions.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

[SOLVED]DATETIME conditional expressions.

Post by JellyFish »

I have a table with a DATETIME field. I would like to select all fields in this table that is larger then the current time minus x seconds/minutes.

For example:

Code: Select all

 
$sql = "SELECT * FROM `table` WHERE `date` > (CURRENT_TIME - X_TIME)"; //Where X_TIME is a few seconds or minutes.
 
This will allow me to select all records that are only moments new.

Thank you for taking the time to read this post.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Re: DATETIME conditional expressions.

Post by JellyFish »

Ok nevermind I figured it out.

Code: Select all

 
$sql = "SELECT * FROM `table` WHERE `date` > NOW() - INTERVAL 2 MINUTE";
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: [SOLVED]DATETIME conditional expressions.

Post by califdon »

When you have solved your problem, PLEASE return to your original post, edit it and add the word [SOLVED] to the Subject. I have done that for you, this time.
Post Reply