every file has a 'timestamp' which tells when was created
if you store each message in a separate file, you can test this time that file was made
this test function is http://php.net/filemtime
$filename = 'myfile.txt';
// this gets timestamp value of file
$time = filemtime( $filename );
echo $time."<br>";
// this get a string: ->yymmdd 140523<- where is clock: 14:15:23
$string = date ( "ymd His", filemtime( $filename ) );
echo $string."<br>";
But most simply, you should add a timestamp value with every message
http://php.net/time
$time_posted = time();
echo $time_posted."<br>";
$string = date( $time_posted );
echo $string."<br>";