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
https://forums.phpfreaks.com/topic/15767-calculating-times/
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
https://forums.phpfreaks.com/topic/15767-calculating-times/#findComment-64460
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
https://forums.phpfreaks.com/topic/15767-calculating-times/#findComment-64473
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.