Search code examples
sqltimestampsql-timestamp

How to convert the string as timestamp


$current_date=date('Y-m-d');
$time = strtotime("$current_date -0 years -0 months -1 days");
$date = date("Y-m-d", $time)."<BR>";

the $date holds 2015-10-08 as value. but when i use this value in sql statement, it does not pull records. i did this.

$x=mysql_query("SELECT COUNT(id) from table_name WHERE registration_date='$date'");
$y=mysql_fetch_row($x);
echo $y[0];

It does not pull records.. however if i replace $date with 2015-10-08 .. it does fetch a value from sql


Solution

  • Educated guess > you used "echo $date" and didn't noticed it ended with

    <br>
    

    which is an empty newline

    use var_dump($date) to see any unneeded newlines,whitespace and tags