473,509 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time stuff calculating with time

The1corrupted
134 New Member
I need help with this little time function. After thirty minutes, I want an echo to occur...

[PHP]
$_SESSION['idlemin']=date(i); //This makes the session update each time the page is refreshed but was defined on log in.
$minutes=date(i); //Current
if ($_SESSION['idlemin']>=$minutes+30) {
echo "Your time is up!";
}
[/PHP]

Now, I know this doesn't work for obvious reasons...
Say you logged in at 14:49 well, it would have to equal 14:79 to work and well, time isn't calculated that high so I need something that can spill over hours..
Mar 9 '07 #1
11 1755
ronverdonk
4,258 Recognized Expert Specialist
Taking the server time use the strtotime function, e.g.

[php]echo "30 minutes from now = " . date("H:m:s", strtotime("+30 minutes"));[/php]
Ronald :cool:
Mar 9 '07 #2
The1corrupted
134 New Member
Cool! Thanks.
Mar 9 '07 #3
ronverdonk
4,258 Recognized Expert Specialist
Welcome.

Ronald :cool:
Mar 9 '07 #4
The1corrupted
134 New Member
Taking the server time use the strtotime function, e.g.

[php]echo "30 minutes from now = " . date("H:m:s", strtotime("+30 minutes"));[/php]
Ronald :cool:
Tiny syntax error though...
[PHP]date("H:m:s", strtotime("+30 minutes"))[/PHP]
should be
[PHP]date("H:i:s", strtotime("+30 minutes"))[/PHP]
Mar 9 '07 #5
ronverdonk
4,258 Recognized Expert Specialist
Sorry, my mistake. That's what you get when trying to do it without looking at the manual.

Ronald :cool:
Mar 9 '07 #6
The1corrupted
134 New Member
Another quickie on time.. could you compare times?
[PHP]
$idletime=$_SESSION['idle'];
if (date("H:i:s")>=$idletime) {
echo "<META HTTP-EQUIV='refresh' content='0; url=idleout.php'>";
} elseif (date("H:i:s")<=$idletime) {
$idletime=date("H:i:s", strtotime("+30 minutes"));
}
[/PHP]
And on a different page...
[PHP]$_SESSION['idle']=date("H:i:s", strtotime("+30 minutes"))[/PHP]
Mar 9 '07 #7
ronverdonk
4,258 Recognized Expert Specialist
Why would you format the timestamp in this case. It would be sufficient to just use the Unix timestamp and calculate and compare with that. The format makes it rather difficult.

Ronald :cool:
Mar 9 '07 #8
The1corrupted
134 New Member
Do you mean that gigantic interger gotten when you use the $_SERVER['request_time'] function?
Mar 9 '07 #9
ronverdonk
4,258 Recognized Expert Specialist
It is just the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

But yes, that is the time format I mean. In your case the 30 minutes is just 1800 seconds.

Ronald :cool:
Mar 9 '07 #10
The1corrupted
134 New Member
Actually, I've found what I wrote to work perfectly fine, suprisingly.. Just changed minutes to seconds for the test and it works.
Mar 9 '07 #11
ronverdonk
4,258 Recognized Expert Specialist
When it works: stick with it.

Ronald :cool:
Mar 9 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1676
by: Ken | last post by:
Hello Anyone know of a site with tutorial on calculating the steps in program or in a pseudo code: Ex: for( int =0 ; i<n ; i++) so int=0 will be executed once / i<n will be executed n...
6
2715
by: Michael Bulatovich | last post by:
I have a very simple db I use for keeping track of hours, tasks, projects, clients etc. It has a form that I use to enter data. Currently the form has a textbox for a field called "start time",...
5
1758
by: Carlos | last post by:
Hi all, I have used the datetime class, but I just came up with a situation that need to have some advise. If I now how much time have passed, can I know the original date?. Lets say that I know...
3
2173
by: vashwath | last post by:
Hi all, I have written program for calculating the execution time of a function.Any critics (on the method of calculating execution time) are welcome. #include <stdio.h> #include <time.h>...
4
2198
by: Ravi Ambros Wallau | last post by:
Hi: We developed a set of ASP.NET Web Applications that never runs in stand-alone mode, but always inside a portal (Rainbow Portal). All modules are copied on that portal. My question is: load...
1
4812
by: ret4rt | last post by:
Hello. I have a task to do which is as follows: I have to do an "id query" on a primary key of my db and then calculate the response time of the query. Task says that i'm able to take screenshots...
25
4995
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for...
9
1273
by: James Turk | last post by:
Hi, I have a situation where I have some class members that should only be done once. Essentially my problem looks like this: class Base(object): dataset = None def __init__(self, param):...
2
8890
by: anto.anish | last post by:
Hi - I have been using clock() for calculating CPU time and time() for calculating Wall time. However, since time() does not provided milli/ microsecond accurancy, i started using...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.