Jump to content

Calculating times


Tandem

Recommended Posts

*please skip to my latest reply*

Ok, i'm tryin to calculate the difference between two times. One is a small distance into the future and is in the format(0000-00-00 00:00:00). Lets call this x.

The other is the current time, lets call this y.

I want to calculate how long it will be until y = x.

How should i go about doing this?

If you need more info just ask.
Link to comment
Share on other sites

check out the [url=http://us3.php.net/manual/en/function.time.php]time[/url] function. This should point you in the right direction

or here is an example straight out of the [url=http://us3.php.net/manual/en/function.time.php]manual[/url]

[code=php:0]<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
                  // 7 days; 24 hours; 60 mins; 60secs
echo 'Now:      '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
?> [/code]
Link to comment
Share on other sites

How do i subtract the date from a variable date using single quotes?

Both are in the same format, i just don't know the syntax of single quotes and periods very well and am not sure how to use it in this situation.

e.g echo 'today '. $time2 .' - '. date('Y-m-d H:i:s') ."\n";

What should i change this to to make it actually calcualte the answer?
Link to comment
Share on other sites

Without seeing all your calculations, this is the best I can do....

Something along these lines should work

[code]$mins = $totalSec / 60;
$leftoverSec = $totalSec - ($mins * 60);

echo "$mins m $leftoverSec s";[/code]
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.