Re: [PHP] Subtracting dates w/o database interaction (MySQL)

2005-09-23 Thread Stephen Leaf
$date = mysql date field 2005-09-23 for example
$difference =ceil((strtotime($date) - time()) / 86400);

strtotime is far nicer than mktime when you already have a date field ready.

On Friday 23 September 2005 03:10 pm, Philip Thompson wrote:
> On Sep 23, 2005, at 11:16 AM, Chris W. Parker wrote:
> > Philip Thompson 
> >
> > on Friday, September 23, 2005 9:12 AM said:
> >> I'm needing to find the number of days between two dates without
> >> using an database functions (DATE_SUB, etc)... only PHP. Is there an
> >> easy way to accomplish this? I have searched the PHP site, but have
> >> not been successful in finding anything that will assist me.
> >>
> >> Any help would be appreciated.
> >
> > There might be an easier way but... convert to timestamp, subtract
> > smaller number from bigger number, figure out how much time has
> > passed.
> > Chris.
>
> I actually discovered how to do this right after I made the post. I
> looked at some archives and worked this out.
>
> 
>
> // today - 9/23/05
> $start = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
>
> // the objective day - 3/15/06
> $end = mktime(0, 0, 0, 3, 15, 2006);
>
> // subtract today from the objective and divide by 24*60*60 to get days
> $difference = ceil(($end - $start) / (86400));
>
> 
>
> Thanks for your assistance.
> ~Philip

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Subtracting dates w/o database interaction (MySQL)

2005-09-23 Thread Philip Thompson

On Sep 23, 2005, at 11:16 AM, Chris W. Parker wrote:


Philip Thompson 
on Friday, September 23, 2005 9:12 AM said:


I'm needing to find the number of days between two dates without
using an database functions (DATE_SUB, etc)... only PHP. Is there an
easy way to accomplish this? I have searched the PHP site, but have
not been successful in finding anything that will assist me.

Any help would be appreciated.



There might be an easier way but... convert to timestamp, subtract
smaller number from bigger number, figure out how much time has  
passed.

Chris.



I actually discovered how to do this right after I made the post. I  
looked at some archives and worked this out.




// today - 9/23/05
$start = mktime(0, 0, 0, date("m"), date("d"), date("Y"));

// the objective day - 3/15/06
$end = mktime(0, 0, 0, 3, 15, 2006);

// subtract today from the objective and divide by 24*60*60 to get days
$difference = ceil(($end - $start) / (86400));



Thanks for your assistance.
~Philip

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Subtracting dates w/o database interaction (MySQL)

2005-09-23 Thread Gustav Wiberg
- Original Message - 
From: "Philip Thompson" <[EMAIL PROTECTED]>

To: 
Sent: Friday, September 23, 2005 6:11 PM
Subject: [PHP] Subtracting dates w/o database interaction (MySQL)



Hey all.

I'm needing to find the number of days between two dates without  using an 
database functions (DATE_SUB, etc)... only PHP. Is there an  easy way to 
accomplish this? I have searched the PHP site, but have  not been 
successful in finding anything that will assist me.


Any help would be appreciated.

Thanks,
~Philip

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.5/110 - Release Date: 2005-09-22



Hi there!

Take a look at 
http://www.varupiraten.se/opensource/doc.php?subject=datefunctions.php#datefunctions.php

I hope this will help you... :-)

/G
http://www.varupiraten.se/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Subtracting dates w/o database interaction (MySQL)

2005-09-23 Thread Chris W. Parker
Philip Thompson 
on Friday, September 23, 2005 9:12 AM said:

> I'm needing to find the number of days between two dates without
> using an database functions (DATE_SUB, etc)... only PHP. Is there an
> easy way to accomplish this? I have searched the PHP site, but have
> not been successful in finding anything that will assist me.
> 
> Any help would be appreciated.

There might be an easier way but... convert to timestamp, subtract
smaller number from bigger number, figure out how much time has passed.



Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Subtracting dates w/o database interaction (MySQL)

2005-09-23 Thread Philip Thompson

Hey all.

I'm needing to find the number of days between two dates without  
using an database functions (DATE_SUB, etc)... only PHP. Is there an  
easy way to accomplish this? I have searched the PHP site, but have  
not been successful in finding anything that will assist me.


Any help would be appreciated.

Thanks,
~Philip

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] subtracting dates...

2003-08-02 Thread John Ryan
yeah, thats the code i wrote myself (nearly). it gets the job done.
thanks

"Curt Zirzow" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> * Thus wrote John Ryan ([EMAIL PROTECTED]):
> > Hi,
> >
> hello ryan,
>
> > In mySQL, I store dates as -MM-DD, a standard DATE type. It stores
users
> > date of births. I need to calculate in a PHP script, the users age from
this
> > DOB. I get a PHP date in the same format as the mySQL and subtract,
which
> > returns the year rounded off. ie, it doesnt matter if your birthdays in
june
> > of 1983 and the date is januray 2003, your age is still returned as 20,
when
> > it should be 19.
> >
> > Does anyone know how can i get the right age?
>
> To get a real age of someone you would use seconds, but since the actual
> count of seconds get messed up on leap years (through the convertion
> from seconds to years),  I approached it with the method most people
> calculate ages.
>
> Most people first look at the year and find the differnce, then if
> the month/day hasn't come around you subtract one; alas the common
> calculation for age.
>
> Here is the code to demonstrate that logic:
>
>
> $dob = split('-', '1980-12-1');
> $now = split('-', date('Y-m-d'));
>
> // we are either this age or one less
> $age = $now[0] - $dob[0];
>
> // have we gotten to the month of in dob?
> if ($now[1] < $dob[1]) {
>
>// no, so we are technically a year less.
>$age--;
>
> // If we're in the month,  has the day come yet?
> } elseif ($now[1] = $dob[1] && $now[2] < $now[3]) {
>
>// no, still a few more days.
>$age--;
> }
>
> // your age is proper, in day to day usage.
>
> /*
>   Note:
>
>   instead of the if () elseif() you can use
>   if (mktime(0,0,0,$now[1],$now[2]) < mktime(0,0,0,$dob[1],$dob[2])) {
> $age--;
>   }
>
> */
>
>
> HTH,
>
> Curt
> --
> "I used to think I was indecisive, but now I'm not so sure."



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] subtracting dates...

2003-08-02 Thread Curt Zirzow
* Thus wrote John Ryan ([EMAIL PROTECTED]):
> Hi,
> 
hello ryan,

> In mySQL, I store dates as -MM-DD, a standard DATE type. It stores users
> date of births. I need to calculate in a PHP script, the users age from this
> DOB. I get a PHP date in the same format as the mySQL and subtract, which
> returns the year rounded off. ie, it doesnt matter if your birthdays in june
> of 1983 and the date is januray 2003, your age is still returned as 20, when
> it should be 19.
> 
> Does anyone know how can i get the right age?

To get a real age of someone you would use seconds, but since the actual
count of seconds get messed up on leap years (through the convertion
from seconds to years),  I approached it with the method most people
calculate ages.

Most people first look at the year and find the differnce, then if
the month/day hasn't come around you subtract one; alas the common
calculation for age.

Here is the code to demonstrate that logic:


$dob = split('-', '1980-12-1');
$now = split('-', date('Y-m-d'));

// we are either this age or one less
$age = $now[0] - $dob[0];

// have we gotten to the month of in dob?
if ($now[1] < $dob[1]) {

   // no, so we are technically a year less.
   $age--;

// If we're in the month,  has the day come yet?
} elseif ($now[1] = $dob[1] && $now[2] < $now[3]) {

   // no, still a few more days.
   $age--;
}

// your age is proper, in day to day usage.

/*
  Note:
  
  instead of the if () elseif() you can use
  if (mktime(0,0,0,$now[1],$now[2]) < mktime(0,0,0,$dob[1],$dob[2])) {
$age--;
  }

*/


HTH, 

Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] subtracting dates...

2003-08-02 Thread John Ryan
Hi,

In mySQL, I store dates as -MM-DD, a standard DATE type. It stores users
date of births. I need to calculate in a PHP script, the users age from this
DOB. I get a PHP date in the same format as the mySQL and subtract, which
returns the year rounded off. ie, it doesnt matter if your birthdays in june
of 1983 and the date is januray 2003, your age is still returned as 20, when
it should be 19.

Does anyone know how can i get the right age?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Subtracting dates in php

2003-07-01 Thread Boaz Yahav
Try : 

Difference between two dates (i.e. between today and a date in future).
The program is based on php-timestamp, but in your browser you see the
usual dates(i.e.: dd.mm.)
http://examples.weberdev.com/get_example.php3?count=3240

Find the Difference between today's date and a future day.
http://examples.weberdev.com/get_example.php3?count=3198

how can I output the difference between two dates?
http://examples.weberdev.com/get_example.php3?count=95


Sincerely

berber

Visit http://www.weberdev.com/ Today!!!
To see where PHP might take you tomorrow.

-Original Message-
From: Mike Mannakee [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 01, 2003 7:22 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Subtracting dates in php


Anyone know of an easy way to add or subtract dates in php the way you
can in mysql?  Easier, that is, than coding the logic by hand?  This
seems like a total pain.

Mike



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Subtracting dates in php

2003-07-01 Thread David Otton
On Tue, 1 Jul 2003 01:21:54 -0400, you wrote:

>Anyone know of an easy way to add or subtract dates in php the way you can
>in mysql?  Easier, that is, than coding the logic by hand?  This seems like
>a total pain.

Convert to Unix timestamps, do regular maths, unconvert.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Subtracting dates in php

2003-06-30 Thread Mike Mannakee
Anyone know of an easy way to add or subtract dates in php the way you can
in mysql?  Easier, that is, than coding the logic by hand?  This seems like
a total pain.

Mike



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] subtracting Dates

2001-05-01 Thread Gyozo Papp


> Hello,
> For instance today is 05-01-2001 I would like to
> determan the previous 7 days from that date.  In VB
> Date - 7 = 04-24-2001  I would like this to work for
> any date using php.
> Here is what I have so far...
> $t = (date ("m-d-Y"));
> echo $t; // output 05-01-2001
> echo "";
> $r = $t - 7;
> echo $r; //output -2
> but now $r returns -2
> How do I get $r to yesterdays date in this format.
> 04-30-2001

 see the php manual: (Function Reference / XV. Date and Time functions) 
a piece of description & examples about date() function:

$tomorrow  = mktime (0,0,0,date("m")  ,date("d")+1,date("Y"));
$lastmonth = mktime (0,0,0,date("m")-1,date("d"),  date("Y"));
$nextyear  = mktime (0,0,0,date("m"),  date("d"),  date("Y")+1);

date() with mktime() is more than perfect. After subtracting date parts with the help 
of date()  you pass them to mktime... 
and you can deal with its arguments as integers.(see ie: $tomorrow).


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] subtracting Dates

2001-05-01 Thread Mike Mike

Hello,
I am trying to make a hit counter graph that will have
7 days to it. Monday thru Friday.
I'm having problems getting the last 7 days. 
For instance today is 05-01-2001 I would like to
determan the previous 7 days from that date.  In VB
Date - 7 = 04-24-2001  I would like this to work for
any date using php.
Here is what I have so far...
$t = (date ("m-d-Y"));
echo $t; // output 05-01-2001
echo "";
$r = $t - 7;
echo $r; //output -2
but now $r returns -2
How do I get $r to yesterdays date in this format.
04-30-2001
Thank you
  --Mike

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]