I would say use two queries:
$query = 'SELECT COUNT(*) FROM `myTable`';
$exec = mysql_query($query);
$num_rows = mysql_result($exec, 0);
$query = 'DELETE FROM `myTable` ORDER BY `datetime_column` DESC LIMIT ' . ($num_rows - 5);
$exec = mysql_query($query);
NOTE: Code is untested... might want to use this in a test environment first 😉
EDIT: Also, to explain - the $num_rows - 5 bit is where you set how many rows you want to keep in the database... it's basically saying "Delete all rows except for 5 of them" so you'll want to adjust this number to your liking.