Reply to Comparing Two Dates Using PHP from MYSQL Database

Your name:

Reply:


Posted by ameshkin on 11/18/15 11:44

Hi GUys,
Im trying to compare two dates in MYSQL. But its not treating the
dates as numbers, but as strings. I try using strtotime but that did
not work.

Basically, if the last comment is newer than the last user login, then
I need for a message to pop up and say New Comments.

If not, then no new comments. The area of this code which is not
working is at the bottom.

Does anyone know how to figure out how to compare these two dates?

mysql_select_db('playlist') or die('Could not select database');


// Performing SQL query
$query = "SELECT *
FROM `Login`
WHERE `loginName` = '$logname'
ORDER BY `loginTime` DESC ";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$row = mysql_fetch_assoc($result);


// Free resultset
//mysql_free_result($result);

// Closing connection
mysql_close($link);



$LastLogin = $row['loginTime'];



//second task is to pull last comment

$link2 = mysql_connect('localhost', 'premium', 'amir18')
or die('Could not connect: ' . mysql_error());

mysql_select_db('premium') or die('Could not select database');


// Performing SQL query
$query2 = "SELECT *
FROM `comments`
WHERE `owner` = '$logname'
ORDER BY `timestamp` DESC ";
$result2 = mysql_query($query2) or die('Query failed: ' .
mysql_error());
$row2 = mysql_fetch_assoc($result2);


// Free resultset
//mysql_free_result($result2);

// Closing connection
mysql_close($link2);

echo "<br>";
//echo $row2['timestamp'];


$LastComment = $row2['timestamp'];

//CONVERT TIMESTAMP INTO a date form
$date = $row2['timestamp'];
$year = substr($date,0,4);
$month = substr($date,4,2);
$day = substr($date,6,2);
$hours = substr($date,8,2);
$minutes = substr($date,10,2);
$seconds = substr($date,12,2);
$timestamp = mktime($hours, $minutes, $seconds, $month,
$day,
$year);
$convertedTime = date("Y n d", $timestamp);
strtotime('$convertedTime');
echo $convertedTime;
ECHO "<BR>";

strtotime('$LastLogin');

echo $LastLogin;


if (strtotime('$convertedTime') > strtotime('$LastLogin')) {
echo "New Comments";
} else {
echo "There are no new comments";
}

?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация