-2

I want to know how to display time since a user has submitted the form on my website. So for example when the user submits the form I was to display

"Thank-you for your submission. You have been logged in for 0 seconds" depending upon the time that has elapsed." Can I use the time() function but am not sure to process it.

ja si
  • 13
  • 1
  • 1
    When the form loads, save that timestamp in a hidden field then post it to your PHP page and when you output the thank you message get a timestamp again, compute and display the difference :) – Hanky Panky Jun 02 '15 at 06:16
  • how to create the timestamp. My function time() gives me time since epoch in seconds. – ja si Jun 02 '15 at 06:17
  • Yes that's it. thats all you need. When you have 2 different epoch seconds subtract them then you have the number of seconds elapsed. Then you can divide that by 60 to see the number of minutes – Hanky Panky Jun 02 '15 at 06:18
  • http://php.net/manual/en/function.microtime.php – Umair Khan Jun 02 '15 at 06:18
  • possible duplicate of [Get current date and time in PHP](http://stackoverflow.com/questions/470617/get-current-date-and-time-in-php) – Ritesh Sinha Jun 02 '15 at 06:29

3 Answers3

1

When the user login store the time in a session variable like this:

$_SESSION['usertime'] = time();

Then when the user submits the form you simply minus the current time from that session variable time.

echo "You have been logged in for "  
      . round(abs($_SESSION['usertime']- time()) / 60,2). " minute";
Luthando Ntsekwa
  • 4,192
  • 6
  • 23
  • 52
0

You can use time function like this.

<?php
    $time=time();
    echo($time . "<br>");
    echo(date("Y-m-d",$time));
?>
Luís Cruz
  • 14,780
  • 16
  • 68
  • 100
Mudassar Saiyed
  • 1,146
  • 10
  • 20
-1
echo date("Y-m-d H:i:s");//current date

echo date("H:i:s");//current time

you can search in net before ask:D