Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Doing Time Calculations...


For a project I am working on right now I need to be able to calculate the
time difference between to given times.
(For example...The difference between 11:30 am and 1:45pm being 2:15)

Right now the input is setup as 2 text boxes, 2 dropdowns, and 2 radio
groups. The text boxes get the hour entered into them, the drop downs holdd
a list contaning 00, 15, 30, and 45 (the minutes) and the radio groups being
am or pm.

Is it possible to use that configuration and somehow get the time
difference? or do I need to change the input? The goal is to be able to
enter the two values and immediately see a calculated difference in a third
textbox on the page.

I'm thinking something like....
User enters hour in first text box(textHFrom) - 11
User selects minue value from second dropdown(cboMFrom) - 30
User selects am/pm from radio group(radioF) - am
User enters hour in second text box(textHTo) - 1
User selects minue value from second dropdown(cboMTo) - 45
User selects am/pm from radio group(radioT) - pm

onChange of second RadioGroup time is calculated and result in inserted into
third text box(textHours) - 2:15

I'm not sure if/how to bet do this.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Time Calculations
i have a field in mysql which contains a timestamp: 2007-07-25 22:52:14 i was going to add a new variable but adding 1 hour to it so it would read: 2007-07-25 23:52:14
im not sure how to format the date to read add 1 hour to the date stamp.

Calculations
i want it to calculate a value that is in the db if the db has the value 6 pound(s) (i have a submit button) and the users enters in the input box a value for more pounds then how do i make it calculate in fractions or even divisions.. cause see this is what i have. PHP Code:

Calculations
<?php
echo 04 - 1;
?>

that echo's
3
I need it to echo 03, is there an easy way to do this?

Binary Calculations
I'm not sure if PHP can do this but I have a client that would like to provide unlock codes for a CD they have. They have given me a document that describes the Binary calculation that is required to calculate the unlock code based on the CD serial number. They also refer to EX/OR or exclusive or. The also refer to hex data which I'm assuming is hexidecimal which I'm pretty sure PHP can deal with.

I'm interested in finding out if PHP can work with binary, ex/or and hexidecimal data. If not any other possible solution, ie. library or other language such as Perl. I would also appreciate any links to additional info.

Auto Calculations
I've seen on a few sites that in a shopping enviroment if you choose a price from a drop down and then maybe a delivery ares, the actual price shown for the product is updated instantly without page refresh.

Date Calculations
in my script i have this varaibles PHP Code:

Calculations With Date
i've got 2 date values, both in the format yyyy-mm-dd, has anyone any ideas how to perform a calculation, so that I can take one date away from the other and be left with the days/difference between

Calculations Within A Field
i have a field which is float, it stored the price of an item, i need to create another field called points which times the price by 0.1 and stores that value.

how would i do this? can the sql database do it itself or would i need to create a function in php that will convert it then store the points?

Date Calculations
I'm doin the old calculate persons age from database routine. Had a good search around and found out about Unix timestamps. Been looking those up and trying to figure out how to use them properly.

My dates are of the d-m-Y format.. I.E.. today is 11-02-2007
I did it this way so i can use date("d-m-Y") to grab todays date elsewhere in the site and it's all the same format.

Problem is that I can't quite grasp timestamps.
I tired something like this..

$dobts = strtotime($dateofbirth);
$todaysdate = date("d-m-Y");
$todaysdatets = strtotime($todaysdate);

$agets = $todaysdatets - $dobts;

$age = date("d-m-Y", $agets);

Didn't work of course but it thought that was the point of these timestamps?

Date Calculations?
I'm having trouble with a simple date calculation. Basically I have to time stamps, $todays_date and $date_joined. I want to find out how long a member has been registered on my forum in days months years atm I'm taking  $date_joined off $todays_date but its giving me an actual date which is 1971-06-05 but I actually want something like 30 days or 2 months 3 days not the actual date if that makes any sense.

Heres my code:
$todays_date=time();
$date_joined=$member_row['user_joined'];
$join_time=$todays_date-$date_joined;
echo "Join time: ". date('Y-m-d', $join_time)."
";

How To Do Calculations Using JOIN Statement?
I have three tables -:

Customer Table
AccountID field
Name field

Invoice Table
InvoiceID field
invoice_date field
CustomerID field
Amount field

Payment
InvoiceID field
Payment_Amount field
payment_date field

PHP Code:

PHP And MySQL Date Calculations
I have a date type in mySQL, and I want PHP to run a select where it grabs todays date, checks against my database, and returns all values that are new within 30 days. I cant seem to find any help anywhere. Here's what I got so far for it:

$current = getdate();
$this_month = $current["mon"];

that will at least get me the month, the problem is testing it against the date type in the select statement.

Date Calculations Advice
I am getting the date like this $date = strtotime(date());
ok, there you have it, a Unix time stamp of the time, date, and everything else.
From here, is this the best way to do calculations.

Like if I wanted to tell when 48 hours had passed from this date, how do I go about doing that. I know for example if you wanted to add a day, you check on how many "number's" here are in a day and put + that number onto the strength.
Can someone tell me some stuff about this, so I am more familiar with dates, before I start all of these calculations.

Simple Date Calculations
What I am trying to do is show the difference between two dates - one will be "today" and the other will be the date on which an entry was made into the database for that particular user.

I tried doing $difference = $today - $entrydate but this did not give me any kind of figure. Both dates are stored in the format of, for example, 21 Feb 07, 11:22am Would the time cause problems?

Deduct Date/time From Daste/time To Display Hours/days Difference
what i'm wanting to do is take away date logged from date closed therefore leaving the time between the 2 date/time stamps so that i can work out the average time later on and display as average time: 1day 2hours .

Problems With Php Date/time - Real Time Clock
On my website i would like to have a real time clock....i mean to show seconds
running one after another...how can i do this?

Another problem is how to get time into a variable (which then i will insert
into a database table)?

Adjusting Time Displays For User's Local Time
I have a news/comment site where stories and comments are accompanied by the date they were posted. Currently I'm doing that in the GMT format, simply because it's easiest.

What I'd like to do, however, is have the page display posts and comments with "your time," i.e., the local time of the user (example of what I'm talking about here).

I know how to get local time variables from a user with javascript, but I'm not sure how to pass that information to PHP, especially since I'd like to do this on the front page, which means no passing javascript information via query strings.

Determining If Time Falls Into Time Frame
I am having problems determining whether the current time falls into a certain time frame. I want to be able to allow my users to set a start and end time of when they do not want to be disturbed.

for example: between 11pm and 3am every day. I would then store this as 23:00:00 and 03:00:00 in a table. If the times were on the same day then this code would work:
PHP Code:

Formate Date And Time To Time Stamp
How can I transform the out put of a date() function into a timestamp e.g date(H:i:s)

Convertint Time String To Time Stamp
I want to convert the time string from the if-modified-since header
into a unix time stamp, so I looked at the strtotime() function. The
PHP manual on that function makes reference to a GNU manual page,

which indicates that only UTC and Z are unambiguous. However, a
last-modified-header is followed by "GMT". They are synonymous, but
can I safely use it with strtotime()?

Displaying Time In Different Time Zones
I'm trying to get to grips with times, and as an exercise am trying to
create a function to display the time in various places.

The way I'm currently doing this is as follows:

// -------------------------------
putenv("TZ=GMT"); //set to GMT
$time_to_convert = mktime(15,0,0); //gives me 3pm GMT

echo(strftime('%d/%m/%y %H:%M',$time_to_convert)); //3pm

putenv("TZ=CET");
echo(strftime('%d/%m/%y %H:%M',$time_to_convert)); //7pm
// -------------------------------

That seems to work fine, and gives me the dates in the various places.
The question I have, is how can I determine if a given country is in
daylight-savings?

Essentially, what I want to achieve is a list that will tell me what
time it is in a given country right now. (A bit like the World Clock

Time Difference Change Over Time
Is there a way to print the time different depending on how long the time has been. So like if the user has not been logged in for 24 hours or more... it will say 1 day rather than 24 hours. And if its less than 1 hour it will say it in minutes... and if its greater than 1 hour but less than 1 day it will say minutes and hours?

This is my query which i have done so far but don't know how to do the above checking!

//get register date and now date
$GetLoginDate = mysql_query("SELECT DATEDIFF(NOW(), LoginDate) AS LastLogin FROM userregistration
WHERE  UserID='{$_SESSION['Current_User']}'")
or die(mysql_error());
$lastlogin = mysql_fetch_assoc($GetLoginDate);

Show Time In Local Time
I tried searching for the answer, but didn't really get anything back. Maybe it's the terminology I was using.

Can anyone help me in a direction for how to change what time zone a time is displayed for? My timestamps default to California and would like to show them as EST.

Or even show the time in whatever time zone the person viewing the time is in. Does that sentence make sense?

PHP To Select Chance - 50% Of Time X - 50% Of Time Y
I'm sure this is very simple, and I believe has something to do with generating random numbers (although I could be wrong).

What I need is simple, code that will show picture X 50% of the time, and picture Y 50% of the time. So that  the views on each picture will be exactly the same.

Date & Time Fields To Printed Date/time
How can i take data from date and time field and convert:

2003-02-26 to 26th of Febuary 2003

And: 19:25:00 to 7:25 PM

Php.ini Sets Max Time To 90 Seconds, Yet I Get A "Max Execution Time Of 30 Seconds Exceeded"
This is weird. When I use getId3 to try to read meta tags out of
multimedia files, I get this error:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/
httpd/vhosts/bluewallmultimedia.com/httpdocs/getid3/getid3/
getid3.lib.php on line 54

But if I run phpinfo(), I get this:

max_execution_time9595

and if I ssh to the server and look in php.ini, this is confirmed:

max_execution_time = 95 ; Maximum execution time of each script,
in seconds

This is on a RackSpace server, running RedHat. It's got Plesk
installed.

Switching From 24 Hour Time To 12 Hour Time
In a form I enter a time. The database stores it in a 24 hour format, but I want it to be displayed on the users screen in 12 hour format. For example, Instead of 16:30 I want to have the output displayed as 4:30pm. How do I achieve this? For what it is worth I am using PHP 4.0.4 and mySQL 3.23.22-beta.

Last Time
I have tried posting 3 times today and had every post wiped and a error screen that said "no forum selected" or some such nonsense.

There is some serious problem with posting in this forum as I have had this happen before, on too many occasions.

Time
How to get d server time in php .... and how to fine year(not system date yr) in server side like use of calendar functions...

Time
I would like to view the time when entering my site, in the format: 18:09 Does anybody know a solution for this?

Php - Time Until You Hit
Heya, I havn't worked with the time functions of PHP much, and im having an issue with something i thought would be rather simple.

All i want to do is display how many hours/minutes/seconds are left until you hit 17:30 or 5:30 pm. I thought ok thats easy. Get current time - 17:30. I thought it would work like lets say its 17:00

17:00 - 17:30 = -30 that what i want the - 30 minutes until 17:30

If you do this in PHP with mktime(19,30,00,01,01,1970); and time(); It actually comes out as 10:30. So i tried a range of other things but couldn't seem to get it to just return how long until the time i made. Code:

$thistime = time();
$mktime = mktime(19,30,00,01,01,1970);
$timeuntil = $thistime - $mktime;
<?php echo date("H:i:s a", $timeuntil);?>

Run that and you will see what i mean.

Time!
I just can't catch the drift when dealing with dates and times. First I need a simple script to convert a "human" entered date (ie 12-9-2000) from a form to unix time. Can I use a <input text... >?

Then I need to convert unix time back into a "human" form to display when reading to a page. Again 12-9-2000. All this time I am having trouble setting up mySQL table. Do I set the startdate and enddate columns as INT or TIMESTAMP.

Getting Time?
I have a date in a table like so 2002-03-21. now you can see that it is 2 days and 1 year from today, 2003-03-23 I need to get that date (the old one) and find out how many days it is behind time()

but here is the catch. I have a column that holds a variable on how many months to add to that old date. if there is no field (lets call it renew) then it is just adding a 12 months (1 year) to the old date. so actually the old date could be like this 2001-03-21 with the renew field at 1.

so here is the question. how can I get it? I tired the following code and it is so far out of whack I don't know wha tis wrong. by the code you should see what I want. but if not here I will try to explain. if the final variable is 0 or 1 then I send a email, if the final variable is 0 and I sent an email I send another one to disable the said individual. PHP Code:

Time()
how do I make the time() function display the current time in GMT?

Time.....
I am pretty new to this so forgive me it is it a silly question....
I am setting a 15 minute cookie using time()+900.
This works but I would like to inform the user of the expiration time in a
hh:mm format...

What I need to know is how to convert time()+900 into HH:MM.

How To Get UTC Time In PHP 4?
How can I get UTC time in PHP 4?

Time Log App
I am writing an application that an IT support company can use to log time everytime they visit a customer which will then get the customers 'allocated monthly hour allowance' and remove the time the log from this.

It is only a relatively simple app but I am having trouble with the following code that I have attached. The hours are stored in the database in decimal format and I have got the attached code to convert the decimal value into hours and minutes and show it in HH:MM format.

I want to be able to split the text box which the IT tech enters their time (currently they still have to enter in decimal format) into two boxes HH and MM so that it is easier for them to do so.

I would also like the code to automatically remove this data from the database - currently the code I have written only works out the time left on the maintenance contract if you include the previous hours you have entered. For example - if I had been working somewhere for an hour and a half today but worked three hours yesterday I would have to put 4.5 into the text box. I want to be able to put 1.5.

Time Of Day
I need to print a section of an html page only if the time is after
5:00am and before 9:00pm local time (Seattle, WA: GMT -0800 during
standard time, GMT -0700 during daylight savings time). I found a
bewildering number of functions for getting local or GMT timestamps,
and formatting them. But I can't find anything that will return the
time of day. Am I missing something obvious? Or must I put together my
own function to get time of day?

Time
anyone know a way to look at say 2007-07-01 and if its over 30 days old switch it to new month?

How To Use PHP Time?
I'm trying to figure out how to get php variables as the time. One variable for the hour and one variable for the minute or one variable for both. Right now im looking at this example that i found on google..

<?php

$localtime_assoc = localtime(time(), true);
print_r($localtime_assoc);

?>

Its outputting..

QuoteArray
(
    [tm_sec] => 24
    [tm_min] => 3
    [tm_hour] => 19
    [tm_mday] => 3
    [tm_mon] => 3
    [tm_year] => 105
    [tm_wday] => 0
    [tm_yday] => 92
    [tm_isdst] => 1
)

So my question is, how do I take the array value's of [tm_min] and [tm_hour] and get them into php integer variables such as $hour and $minute?
Any other easy ways to do this that doesn't involve this code?

PHP Time.
What PHP function or code do i need to get the GB Time. [UK Time GMT] ?

To display on the site?

IF/THEN With Time
I'd like to use an if/then statement on a certain page making it work during certain times. For example, if time is between 6pm - 10am, then A else B, what code would I need for that?

Add Time (10:42:00 +00:25:15)
The format of the time is (10:42:00 +00:25:15).

Time
I am using this for time and date:

$tiempo = date('l dS of F Y h:i:s A',strtotime('tomorrow'));
How would i do this:

If current server time is after 12pm or $miles above 100

$tiempo = date('l dS of F Y h:i:s A',strtotime('tomorrow'));

else

$tiempo = date('l dS of F Y h:i:s A');

Can someone translate this to code? It's the "after 12pm part that i am having trouble with.

if(date('h') > 12pm || $miles >=100){
    $tiempo = date('l dS of F Y h:i:s A',strtotime('tomorrow'));
}else{
    $tiempo = date('l dS of F Y h:i:s A');
}

Time
I am facing problem in converting to time.

select sec_to_time(unix_timestamp(now())-unix_timestamp(timestamp)) from Tablename where name= '".$name."'";

Here when values exceeds 838:59:59 how to get the exact value of time. Other than sec_to_time() is there any other function which gives the exact value

PHP Time()
I need to store in a database the time in one hour. Then i need to pull the stored time out compare it to the current time and display how long left.

If there still is time left until the future time then it should do something and if it has already passed the stored time it should do something else and update the stored time to an hour from now.

This has put a brick wall infront of me and a few work friends as we cannot display the time left or be certain that our whole script works as its is a mess of other peoples and has been scraped.

PHP Time
I tried this code:

<?php

echo date('d'):?>

I thought it would work. but it gives me a error.

Time()
how would I get the number code for date() for exactly 2 months ago?

Php Time ()
I have a script to generate the local time. My local time here is ISD 6:50pm.

This is the script
$timestamp = time() ;
$hr=time();
echo $hr;
$current_time=strftime("%I:%M %p",$timestamp) ;

but i get a time as 1:10pm aand so .not the rite time. is there anythn wrong?


Copyright © 2005-08 www.BigResource.com, All rights reserved