I need to make time difference of 24 hours from registed time.

In my database, there is column datelog with type "timestamp" Default value: CURRENT_TIMESTAMP

I need the result if user with data:

2012-10-02 14:51:41 Test1 Test 2

User must not be able to register for next 24 hours.

Thanks in advanced.

$now = date("datelog");
$one_day = ($now -(60*60*24)); // I want to make sure of 1 day time difference
$query = "SELECT * FROM  `Humeur_log` WHERE  `prenom` =  '".$prenom."' AND  `nom` =  '".$nom."' AND (`datelog` > $one_day)";

Edited by diafol: Just a thread not a snippet

4 Years
Discussion Span
Last Post by PriteshP23

So is this like some sort of testing site, where an user can register to a test - has 24 hours to do so, but can't register for a new test until after that period?

This won't work:

$now = date("datelog");

You probably don't need php.

`datelog` > (UNIX_TIMESTAMP() - 86400)

Should return true if user registered within 1 day

`datelog` <= (UNIX_TIMESTAMP() - 86400)

Should return true if the user is safe to register

I think - my head's shot - getting late.


I just need to test for 24 hours.

This is my table data. This user should not be allow to enter the name for next 24 hours.

logid   FirstName   LastName       datelog      
 293     test       test2     2012-10-29 14:54:33   

Please let me know excatly where i need to modify code so it will work.

Thanks in advanced.


I have tried but it gives message:

Parse error: syntax error, unexpected '`'

SELECT * FROMusersWHEREFirstName= '".$FirstName."' ANDLastName= '".$LastName."' AND (datelog> '".UNIX_TIMESTAMP(datetime) - 86400."')LIMIT 0 , 30

However, this query gives output in PhpMyAdmin databse.

I would like to know the step to get the output.


you can write query without ` and purely in mysql rather than using part of php

$query = "SELECT * FROM  Humeur_log WHERE  prenom =  '".$prenom."' AND  nom =  '".$nom."' AND   current_timestamp >= date_add(datelog,interval 24 hour) ";
Votes + Comments
much better
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.