Shebeer Ahammed
Shebeer Ahammed

Reputation: 21

Search between two dates in mysql and php

Hi I want to search the items present in the table users. The code I wrote is

$fromdate = date("Y-m-d H:i:s", strtotime($_POST['fromdate']));
$todate = date("Y-m-d H:i:s", strtotime($_POST['todate']));

$s="SELECT * FROM logs WHERE dt BETWEEN $fromdate AND $todate  ORDER BY dt DESC ";
$x = mysql_query($s);

But the output is not showing. Please someone help me.

Upvotes: 0

Views: 2512

Answers (2)

Narendrasingh Sisodia
Narendrasingh Sisodia

Reputation: 21437

Need to apply quotes around '$fromdate' and '$todate' as

$s="SELECT * FROM logs WHERE dt BETWEEN '$fromdate' AND '$todate' ORDER BY dt DESC ";

Upvotes: 1

Harut Gabrielyan
Harut Gabrielyan

Reputation: 29

$fromdate = strtotime($_POST['fromdate']);
$todate = strtotime($_POST['todate']);

$query="SELECT * FROM logs WHERE UNIX_TIMESTAMP(dt) BETWEEN $fromdate AND $todate  ORDER BY dt DESC ";

Upvotes: 0

Related Questions