Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 936359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:18:11+00:00 2026-05-15T21:18:11+00:00

Using php I’d like to subtract/minus two times; each time within a separate document

  • 0

Using php I’d like to subtract/minus two times; each time within a separate document and thereafter have php write the result (Result after subtracting the two times) within another single text document or within a html document with no HTML tags, just text. The two times subtracted will determine how long a certain player has played the game on which this script will be used for. Also, when I state the script must subtract two times, that is actually for one player, therefore in overall there should be more than two times subtracted; depending on how many people actually play the game.

If you take a look at the following below, this is a text file containing a player’s user name as well as the local time for a player, followed by other numbers which are irrelevant within this case:

The text file is called "begin.txt":

"AULLAH1" "01/07/2010 15:28 " "55621454" "123456" "123456.00"

"USERNAME" "7/3/2010 6:21 PM" "55621454" "123456" "123456.00"

"AULLAH1" "07/07/2010 15:05 " "55621454" "189450" "123456.00"

"SUPREMEGAMER" "7/8/2010 6:42 PM" "55621454" "123456" "123456.00"

There are two "AULLAH1" user name entries, as this player has played the game twice. The next entry on the first line is "01/07/2010 15:28 " which is the date and current time for the person "AULLAH1". The other data after the date and time are irrelevant, therefore they can be ignored.

Within another text document, titled "end.txt" is the following data, which is in the same format as the previous text file:

"AULLAH1" "01/07/2010 15:54 " "55621454" "123456" "123456.00"

"USERNAME" "7/3/2010 6:49 PM" "55621454" "123456" "123456.00"

"AULLAH1" "07/07/2010 15:32 " "55621454" "189450" "123456.00"

The difference within this text file is that there is no player titled "SUPREMEGAMER" as this player didn’t manage to finish the game. Also, the time is different for those users who managed to finish the game. Player "AULLAH1" is also listed twice as this player has finished this game twice.

I’d like the php script to search the end.txt file for the last entry of user name "AULLAH1" and grab the entire line thereafter again, search for the last entry of "AULLAH1" from begin.txt and then subtract the times. Once it’s subtracted, I’d like the user name as well as time to be written within another text document or within a html document with no HTML tags, just text (as stated earlier). So, this will only show the time played for the user "AULLAH1" therefore, I’d like this process to be done for each and every user name within the end.txt document.

All assistance is appreciated and I look forward to your replies; thank you. 🙂 If I didn’t explain anything clearly and/or you’d like me to explain in more detail, please reply. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:18:11+00:00Added an answer on May 15, 2026 at 9:18 pm

    I’m not going to address the text file searching here. Let’s say that eventually you get the start and end times together. Getting the difference between the two is pretty easy.

    (Of note, I think you have your times reversed. The times in the "end" file are always lower than the times in the "begin" file, and that’s probably not right. Additionally, you seem to be storing the dates in DD/MM/YYYY format, which my examples might not parse correctly because it can be ambiguous for any day prior to the 13th. You may want to store them in YYYY-MM-DD format instead, which is completely unambiguous.)

    Here’s way 1, using plain old unix timestamps.

    // First we have our times in a human readable format. 
    // Let's make them into unix timestamps
    $start_time = strtotime('01/07/2010 15:28');
    $end_time = strtotime('01/07/2010 15:54');
    $difference_in_seconds = $end_time - $start_time;
    // If you need the difference in minutes or hours, you'll need to 
    // do the math yourself.
    echo "That turn took {$difference_in_seconds} seconds to complete.";
    

    Here’s way 2, using PHP’s new DateTime and DateInterval classes. This will only work in PHP 5.3 or better.

    // We have our times in human readable format.
    // Let's make them into DateTimes
    $start_time = new DateTime('01/07/2010 15:28');
    $end_time = new DateTime('01/07/2010 15:54');
    $interval = $end_time->diff($start_time, true);
    echo "That turn took " . $interval->format('%h hours, %i minutes and %s seconds.');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer // creates an autoreleased string fullCmdString = [NSString stringWithString:[inStr stringByAppendingString:add]];… May 16, 2026 at 11:39 am
  • Editorial Team
    Editorial Team added an answer There are two steps to validating an OpenID identifier. One… May 16, 2026 at 11:39 am
  • Editorial Team
    Editorial Team added an answer Your question is not uncommon, whether/when to use exception is… May 16, 2026 at 11:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Using PHP, what's the fastest way to convert a string like this: 123 to
Using PHP and MySQL, I have a forum system I'm trying to build. What
Using PHP, I'm trying to give each specific text its own variable. I believe
Using PHP / MySQL all encoded up as UTF, we have recently had to
I'm using PHP Curl to measure download times for a webpage. I know this
Using PHP, Perl, or Python (preferably PHP), I need a way to query an
Using PHP, and MySql, I am trying to implement this rather snazzy in-place editor
Using PHP, given a URL, how can I determine whether it is an image?
Using PHP and MySQL, I want to query a table of postings my users
Using php's DOMDocument->LoadHTMLFile('test.html'); keeps on returning an error to me, reporting for an error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.