Jump to content

determing time difference between timestamp login and submit with form


webguync

Recommended Posts

Hi,

 

I am using a timestamp in MySQL to determine when a user logs-in and submits data from a form, What I would like to do is determine the time difference between the login and submit timestamps and echo out the results. "The time taken to complete is 45 minutes." for example.

 

How is this done?

 

The timestamp(s) will look something like

2010-05-17 11:32:45

 

Link to comment
Share on other sites

so I would just use SQL to extract the info from the database with $row = mysql_fetch_assoc($result)

 

and display the info, something like

 

<td>{$row['Timestamp']}</td>

 

then where would strtotime need to go? Also, how would I set up the subtraction between the two fields?

 

Thanks

Link to comment
Share on other sites

MYSQL query might be easier.

 

I want something like

SELECT TIMESTAMPDIFF(MINUTE,'2010-05-17 12:26:13','2010-05-17 11:32:45');

 

except will need to use PHP to determine which record to use from WHERE username = '$username' and also the two fields I need to do the addition are in two different tables(Candidates.login_timestamp and Responses.submit_timestamp). Want to be able to echo out the results in PHP

Link to comment
Share on other sites

in that case simply use a couple of session variables to accomplish your task. no need to use the db.

session var1 = login timestamp, var2 = submit tiimestamp , ans (in seconds) = var2 - var1. then some simple math to convert ans to hrs:min:sec

Link to comment
Share on other sites

with the second timestamp submit_timestamp isn't set until the data hits the database. Can I still use the Session variables?

 

The first timestamp for login is set like this.

 

$sql_update ="UPDATE Candidates
          SET login_timestamp = DATE_ADD(NOW(), INTERVAL 2 HOUR)
          WHERE username = '$username'
          AND password = '$password'"; 

Link to comment
Share on other sites

Just using the info in the database fields can I take this row of data.

<td>" . date('F j, Y g:i:sa', strtotime($row["login_timestamp"] )) . "</td>

 

and subtract from another timestamp (submit_timestamp)?...if so what is the proper syntax for that?

 

I tried this, but not working.

 

echo "<tr><th>Completion Time:</th></tr><tr><td>" . date('F j, Y g:i:sa', strtotime($row["login_timestamp"] - ["submit_timestamp")) . "</td></tr>";

 

 

Link to comment
Share on other sites

sorry, but to further clarify. I have two timestamps in two different MySQL tables(Responses,Candidates). I am using SQL to SELECT the two timestamps here.

$sql = "SELECT submit_timestamp,login_timestamp 
        FROM Responses LEFT JOIN Candidates USING (user_id)";

 

trying to determine the difference b/t the time from login to submit in minutes.(this is a form). I have done a lot of google-ing, but haven't come up with any solutions yet.

 

any ideas?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.