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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Subtract Dates And Count The Amount Of Days Between Them?


Is it possible to subtract dates so you can count the amount of days between them?
If so, how?




View Complete Forum Thread with Replies

Related Forum Messages:
COUNT Only Within Last X Amount Of Days
The script should grab only last 7 days of database entries which it does.  Also it also needs to count to see how many times a CD was played, which it also does, but gives overall total and not just within that 7 days. Code:

View Replies !
How To Subtract Dates ?

HOW TO SUBTRACT DATES and get result in days.

Can anyone suggest me how do I get difference in days when subtracting two dates stored as strings in respective variables.

<?php
$fromyear=$_GET['fromyear'];$frommonth=$_GET['frommonth'];$fromdays=$_GET['fromdays'];
$toyear=$_GET['toyear'];$tomonth=$_GET['tomonth'];$todays=$_GET['todays'];
$fromdatetime = $fromyear."-".$frommonth."-".$fromdays;echo $fromdatetime;
echo "<br />";

$todatetime = $toyear."-".$tomonth."-".$todays;echo $todatetime; echo "<br />";
$diff=$fromdatetime-$todatetime;echo "Diff = " $diff; echo "<br />";
?>

Everytime I use this script the only difference I get is when year value is
changed like if $fromyear is 2007-01-01 & $toyear is 1997 -03-15
I get 10 as result only. Nothing for months & years while I want the result to
be 10 years 2 months 14 days.

View Replies !
Subtract Dates
I think I'm overcomplicating things so I thought I'd ask if there is a better way to subtract two dates. Plus, my way is not very accurate.  Its a few days off... Both dates come from MySQL in the format "YYYY-MM-DD".

   $end_date = $row['end_date']; // (2007-10-10)
   $ts = time();
   $start_date = date("Y-m-d", $ts); // (2007-05-28)

   $end = round(strtotime("$end_date")/84000,5);
   $exploded = explode(".",$end);
           $end_date = $exploded[0];

   $start_date = round(strtotime("$start_date")/84000,5);
   $exploded = explode(".",$start_date);
   $start_date = $exploded[0];
   $expiration_in_days = abs($start_date - $end_date);

View Replies !
Subtract 2 Dates/times
I have two dates with times like this:

Start date/time = 2006-01-01 08:12
End date/time = 2006-01-07 10:45

I want to take the End date/time and subtract Start date/time from it. I want the results in days, hours and minutes. Like this example: 4 days, 3 hours and 52 minutes.

View Replies !
Convert The Dates To Strings To Subtract Them?
$expirationdate[0] = 4/15/2005
$startdate[0] = 3/1/2005

I would like to determine the number of days between the above dates.

My approach:
$startdate = strtotime($startdate[0]); // change to a string
$expirationdate = strtotime($expirationdate[0]);
$delta = $expirationdate - $startdate; // $delta = 1110175200

How do I convert $delta to only number of days? // number of days should
equal 45 days

Do I need to convert the dates to strings to subtract them?

View Replies !
Add X Amount Of Days To Date
im tring to add X amount of days to date, when that date is given as a date stamp.

View Replies !
Dates Of $day In The Next $n Days
how would I go about working out the dates (timestamps) of the day $day (e.g. Monday, Tuesday, &c) in the next $n days. So if $day was Monday and $n 28 I would want to find out the dates in the next 28 days that are a Monday.

The problem is that I am not sure about the logic side of the problem. A crude solution that I can think up is doing something like PHP Code:

View Replies !
Days Between Two Given Dates
I have two variables which look like:

$begin = "23-08-05"
$end = "26-08-05"

Now i want also to know the dates between them.

24-08-05
25-08-05

How can i do this?

View Replies !
Count The Amount Of Rows In A Mysql Database
How can i get php to count the amount of rows in a mysql database where the field. type = 5, and then display them as comment 1, 2, 3, 4 etc.

Like the comments on this blog post...

View Replies !
Calculating Days Between Two Dates
I need to calculate the numbers of days (only the number of days) between two days, one a variable $row['user_cp_name'] in the format MM/DD/YY, and another, the current time. I've tried a bunch of tutorials on the internet and none seem to work properly.

View Replies !
Number Of Days Between Two Dates
I have spent forever trying to figure this out.. There has to be a simple way. My dates are in the format m-d-y

06-22-07

I want to know the number of days between 05-23-07 and 06-22-07. this should equal 30. I am trying to figure out how to get that with PHP.

View Replies !
Business Days B/w Two Dates
How do I count the no.of business days between two dates in php.

View Replies !
Days Between Dates Need To Remove -
ive got this SQL, and it works. But i get a - before each number! Its just so i can see members who have been inactive for over xx days. Code:

View Replies !
Calculate Number Of Days Between 2 Dates
How can I calculate the number of days between 2 dates in PHP?

View Replies !
Retrieve Number Of Days Between Two Dates
I am trying to write a script that grabs todays date and then counts the number of days between today and a date in the future. Both the future date and the number of days interval are retrieved from a database (MySQL). PHP Code:

View Replies !
Dates - Detect Groups Of 7 Days
i'm developing a reservation system for a vacation house. the owner has specified that the place can only be rented by the week, check-in is on saturday, then check out must be on some following saturday (doesn't matter how many weeks as long as check-out is on a saturday). i tried to figure out if the user has selected spans of seven days (rented it for 1,2,3 weeks etc...) this way: PHP Code:

View Replies !
Calculate Number Of Days Between Two Dates
I have people posting ads and when the ad is posted I have two fields populated at that time:

date_created
date_expired

With the date expired being 7 days after the date created. Both are in this format: 03/12/07

What I am doing is preventing someone from posting more than one ad per 7 days. I'm validating against their email address for that. But I want to display the date that they would be eligible as well as determine if they are eligible to post or not which would require comparing today's date with probably using the now() function against the date_expired in the database. If the today's date is past then no problem. If not, then it would display an error. Code:

View Replies !
Dates, Daylight Savings And Net Days Worked
I'm trying to mimic the functionality of netdaysworked in excel. The
code below works, except when the date starts during daylight savings
time. what is the number of seconds in a day for a daylight savings
day?

for ($dayval = $startdate; $dayval <=$enddate; $dayval+=$oneday){
if (date(I,$dayval)==0){
echo("daylight savings time<br>");
}

if(date(w,$dayval)==0){
$daysworked = $daysworked+0;
}
elseif(date(w,$dayval)==6){
$daysworked = $daysworked+0;
}
else{
$daysworked++;
}
echo("first day: ".$dayval." number of days ".($dayval/86400)."
lastday : ".$lastday."day of week :".date(w,$dayval)."date: ".date("m-
d-Y",$dayval)." days worked: ".$daysworked."<br><br>");
}

View Replies !
Compare 2 Dates Problem (select * From 2 Days Ago)
I am having a problem with comparing 2 dates with eachother. I wan't to select everything from a table from today and 2 days ago. PHP Code:

View Replies !
Dates - Mysql Database Older Than 7 Days
I would like to delete all the records in mysql database that is older than 7 days.
How do i go about selecting it in the database ( currentdate - 7).

View Replies !
Determining Total Of Days, Hours And Seconds Between Two Dates
If i have two timestamps, is there a built in function to give me the different between the two as days, hours and seconds?

View Replies !
Working With Dates - Set Up A Cron Job That Will Close All Auctions That Are 10 Days Old
I am writing a new auction script for my website and I have everything working except closing the auctions. I have the database set up to record the start time like this:

Field      Type          Default
time     datetime      0000-00-00 00:00:00

I want to set up a cron job that will close all auctions that are 10 days old.  My only problem is I don't know how to write the code the find the 10 day cutoff.  I know I need to somehow take today's day and subtract 10 days from it but I can't seem to find out how.

My plan is once I find that code I will then take that variable and compare it to the time in the database with >.

View Replies !
How I Could Compare Two Dates To Find The Number Of Days That Seperate Them.
I was wondering how I could compare two dates to find the number of days that seperate them. For instance, after a user signs up to my website, they would see a specific message for only a week. Obviously this is easy if they signed up on the 14th and today is the 16th, but what about if they signed up on the 29th, then I need to figure out for the next month.

View Replies !
Count The Number Of Days Between Two Date Variables?
I would like to have a variable with a set date go against the current date, and determine the number of days between the two dates.?

View Replies !
Count Number Of Days In Db By Date Listed...
I have a table with entries and a date stamp in mm/dd/yyyy format. I want to count how many days there were but only counting 1 day if there are say 20 entries for one specific day! In other words lets say there are:

10 entries for 10/05/2007
and
5 entries for 10/10/2007
The count should result as 2 days.

I have tried while loops but they keep causing the browser to not load the page. Here is an example of what I've tried: Code:

View Replies !
Count Records Between Dates?
I use the following code to count the records in my database: PHP Code:

View Replies !
Count Amount Of Rows In Same Query Of Selecting Rows
I am selecting some rows from a table and i wonder if i can count
the amount of rows in that same table in the same query? I tried something like: PHP Code:

View Replies !
When To Subtract When I Extract?
I have a table that this board helped me build. However I still need some help. I have over 50 automotive lenders in my table that all have different rates and "discounts".

Their is a base_rate, special_discount, equity_discount, luxury_discount, and other_discount. I have a simple form that a user would type in score, term, year model, loan to value percentage(ltv), amount to finance.

I can list out all of the available discounts no problem. But what I am trying to do is get a net rate base on the information suppled to me. It might take modifying my table and that is fine with me. Their are 4 possible discounts. 1st is the special_discount. This is to be subtracted always, if it is stored in the record it needs to be subtracted from the base_rate. 2nd is the equity discount. This is to only be subtracted from the base rate if the user typed in a lower ltv than the low_ltv in the record. Also, if they are financing over 25k (luxury discount) some will give .25% off. Any ideas on how this newbie can make it work?

View Replies !
Subtract Time?
my times are set to $date = date('D M d, Y g:i a'); And this works fine posting data to MySQL but how do I get it so that it can take the time posted in the mysql which has the rowname `postdate` and subtract the time now so it can display something like:
"POSTED PIREP 1365 Minutes Ago" You know? Any suggestions?

View Replies !
Subtract Time
I am currently using datetime in mysql was wondering if somebody could point me to a good tutorial so I can figure out how to get:

$timeago = $datetime - now()

Where $timeago will echo something like Posted: 16 minutes ago or 1 day 4 hrs ago etc.

View Replies !
Subtract 100 From Column
What would be the easiest way to this in sql: I need to subtract 100 from column `foo`, but if doing this makes the value of `foo` less than 0, then I need it to add 1 to column `bar`. Is there an IF command that would allow me to do this, or would i have to compare and subtract the values for each row individually?

View Replies !
Subtract Strings
What function simply subtracts one string from another and outputs the result? As in, takes the string 3.145667 and subtracts 3.14 to get 5667. I've tried a few, but for some reason the server didn't recognize the only one I found that seemed to match the description.

View Replies !
MySQL Add/subtract Quantities?
Two mySQL Questions:

1.) how to numerically increase or decrease the value of a mySQL column

2.) what is the best column structure (e.g. "varchar" or "char" etc.)
for speediest increasing/decreasing

Here is the idea:

I sell fruit. I start with 100 apples, 100 bananas, and 100 grapes.
Visitor purchases 8 apples so now I have 92 of them left. What is the
exact mysql query statement that I would use (the following is wrong,
but gives idea what I'm trying to do):

mysql_query("update fruit_table set quantity_left = 92 where fruit =
'apple'");

Also, what would be the best table structure for the quantity part. Is
this the best?
CREATE TABLE fruit_table (
fruit tinytext NOT NULL,
quantity_left int(3) unsigned zerofill NOT NULL default &#3900;'
);

View Replies !
Subtract Time From A Date
I want to get a starttime. To get this I have to subtract the runtime from a
unit e.g. 08:40:15 from a date e.g. 2007-03-29 16:48:30. So the starttime is
2007-03-29 08:08:15.

Is there any function in php to do so, or must I do it by myself?

View Replies !
Find A Way To Subtract Two Times
I have spent the last few hours trying to find a way to subtract two times, none of the information that I find seems relevant to what I am trying to do...  A technician is filling out a form, posting the time he logs in and the time he logs out, both of which are being recorded in the database.

But prior to the UPDATE, I need to calculate how many hours he was there, e.g. 2.5 hours, then post that also ... then multiply that times his hourly rate and post that also, which ultimately gives the times he was there, how many hours total and how much his time cost against the work, but I think I'm getting off subject... here's my latest failure for code. Code:

View Replies !
Group And Subtract Two Tables?
I am trying to do is take two tables group them, count them then subtract the results. I think I may need a table join but I am not sure? Code:

View Replies !
Mysql Command - Subtract (-1)
This code is for use in a shopping cart, I am not sure how to get it to subtract &#391;' from the 'quantity' row in the table.

include("../CMS/script-files/db-connect.php");
    
    $SQL = " UPDATE products SET";
        $SQL = $SQL . " quantity = '??? MINUS 1' WHERE id = '$id'";

        #execute SQL statement
        $result = mysql_db_query($db,"$SQL",$cid);
        
        # check for error
        if (!$result) { echo("ERROR: " . mysql_error() . "
$SQL
");    }
        
        mysql_close($cid);

View Replies !
Add, Subtract Percentage In A Column
I need the query to add all the numbers in a column, then subtract a percentage from it to produce a final number. I came up with this. Code:

SELECT SUM(price)/100*20
FROM style
WHERE collection_month_id = &#3906;-06-a'
GROUP BY collection_month_id;

this gives me 20 percent of the total.

View Replies !
Offering Dates And Booked Dates In A Table As DATE Datatype Using MYSQL.
Availability dates in offering dates except booked dates. For Example: Offering dates are :

01-09-2005 to 27-09-2005
01-11-2005 to 30-11-2005

Booked dates are :

10-09-2005 to 23-09-2005

Availability dates should be

01-09-2005 to 09-09-2005
24-09-2005 to 27-09-2005
01-11-2005 to 30-11-2005

I am storing offering dates and booked dates in a table as DATE datatype using MYSQL.
So, I want the above mentioned availability dates as a result.

View Replies !
Integer Doesnt Subtract Fully
I have a variable set at 10,800 and im trying to subtract it in my query like here:
$Price = 10,800 in this example.

         $subtractMoney = "UPDATE userregistration SET MoneyInHand=MoneyInHand-'$Price' WHERE UserID='{$_SESSION['Current_User']}'";
$result = mysql_query($subtractMoney) or die(mysql_error());
if (mysql_affected_rows() == 0)
{
die('Error ID 0001A, contact admin on the forums immediately about this error!');
}
But the subtraction is only going down by 10. Not 10,800.. although this 10,800 could be any value this was what i used for this example.

View Replies !
Using PHP, To Add/subtract Lines Of Text To A Flat File (xml)?
Is it possible, using PHP, to add/subtract lines of text to a flat file (xml)?

I understand I can use PHP "file write" to create a file, and "append" to add to it - but is there a way to then remove a certain line from it?

I understand this is sort of a content-management issue, but basically I want to give users the ability to manage (add/remove) songs in there XML playlist.

View Replies !
Regular Expression I Would Like To Subtract 1000 From All The Numbers
I have some pages with a bunch of text, within which includes:

top:1234
top:1244
top:1264
etc

I would like to subtract 1000 from all the numbers associated with "top:" only, and no other numbers. Here is my (bad) regex attempt, but alas, it does not seem to work.

$content = preg_replace("/top:([0-9]*)$1/i",${1} - 1000,$content);

View Replies !
Dates In Range Falling Between Existing Dates
The latest quandry I have is that I need to:

a: check whether any dates in a date range entered by a client in a form (datefrom, dateto) conflict with any existing date ranges already in the database.

-this is a check to see whether the dates that a customer is trying to book are not already booked-
Obviously its easy to get the numbers out of the database (i.e. 28/12/2006 or whatever format) and from the form but how to I convert this 'range' actually into a range I can loop through that will return true if any of the dates are the same (i.e. already booked)?

b: is similar in that I want to check how many of the clients entered dates fall into the pre assigned high, mid and low season ranges in the database and multiply each of those days by the corresponding price.

View Replies !
New Record:Column Count Doesn't Match Value Count At Row 1
I get this error when I try to add a new record to my MySQL Database.

"Column count doesn't match value count at row 1"

So after searching through this forum it seems the problem is that the number of columns in my query doesnt match up to the number of columns in my table. Seems fairly easy to fix doesnt it. However my query has exactly the same number of columns as my table, they are also in the same order. Code:

View Replies !
Column Count Doesn't Match Value Count At Row 1 Error
I keep getting the error: Column count doesn't match value count at row 1

My table has 10 fields, and as far as i can see the only one i am not entering any data into is the vid field, which auto_increment. Code:

View Replies !
Count() - Retreive A Count Of A Column.
I'm performing a select statement against my database

SELECT *, COUNT(column)
FROM blah blah blah
WHERE blah blah blah
GROUP BY member

what i'm trrying to do is retreive a count of a column.

i.e.
$variable1 = $record->variable1;
$variable2 = $record->variable2;
$variable3 = $record->variable3;
$variable4 = $record->COUNT($variable3);

I keep getting the white screen of death, caused by the $variable4 line. How do I retrieve a count? the SQL is correct as I've ran it against the database itself in the sql window. but this has me beat.

View Replies !
How To Compare 2 Dates In Mysql As Mysql Treats Dates As String ?
I'm trying to compare two dates in MYSQL. But its not treating the dates as numbers, but as strings. I try using strtotime but that did not work.

View Replies !
Get Dates Between Two Dates, Then Add To Table
I've got a form that inserts data into a database. Basically what it sends is a sets of dates. What I'm wanting is another set of inputs that also sends some dates. But before it adds them to the database I want to query the dates and find all of the dates between the two given ones and add them to the database as well. Code:

View Replies !
How Do You Get A List Of All Dates Between Two Dates More Than A Day Apart?
Say you have two dates, 2005-01-01 and 2005-01-24. I want to get a list or
array or all the date between and including those two dates.

I want to include this list in a query so I need it in a format like:
&#392005;-01-01', &#392005;-01-02',...

View Replies !
Find Dates Between Two Given Dates
is there any way to find dates between to given dates. ie, suppose it is given 01-01-2006 and 04-01-2006 (in dd-mm-yyyy format), want to print the dates from 01-01-2006 to 04-01-2006.

View Replies !
Subtract Time From The Current Server Time
i have a time that i will get from a mysql database (so it will be in mysql format, YYYY/MM/DD HH:MM:SS). what i would like to do is subtract this time from the current server time in order to get the difference between the two times, expressed as 'x days, x hours, x minutes and x seconds'. any pointers or tips on how to do this .

View Replies !
Validation On Amount
I am using a form to let the user enter an amount.
This must be with zero OR with 2 decimals.
I'm using the comma for decimal seperator.
How can I check if the input is valid (ereg or preg_match?) and what is the
exact statement I will have to use?

View Replies !

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