For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > March 2004 > Finding the number of days betwen two dates









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Finding the number of days betwen two dates
Rob

2004-03-19, 12:56 pm

I am developing my first PHP application and would like some help writing a
function to find the number of days between a date stored in a mySQL
database and the current date.

If anyone could help me with this, I would appreciate it.

Thanks.


Steven Stern

2004-03-19, 12:56 pm

On Sun, 14 Mar 2004 17:36:22 -0000 (more or less), "Rob" <me@somewhere.com>
wrote:

>I am developing my first PHP application and would like some help writing a
>function to find the number of days between a date stored in a mySQL
>database and the current date.
>
>If anyone could help me with this, I would appreciate it.
>
>Thanks.
>


Pardon my snippiness, but I've been working in PHP all of three ws and
learned the first rule of coding:

Google is your friend.

http://groups.google.com/groups?hl=...tes&sa=N&tab=wg

Second thing I've learned is that you can go over to Barnes and Noble or
Border's, buy a small cup of coffee and read a really good book without having
to buy the book. Look at Advanced PHP Programing by Schlossnagle


torch_bearer@hotmail.com

2004-03-19, 12:57 pm

(date("U") - date("U",$stored_date))/(60*60*24)

This will first find the difference in seconds, then divide it by the amount of seconds in a day,
of course you can use 86400 to save on the muliplication costs. This assumes that stored_date is a
timestamp otherwise you'll need to make one with mktime.

> I am developing my first PHP application and would like some help writing a
> function to find the number of days between a date stored in a mySQL
> database and the current date.
>
> If anyone could help me with this, I would appreciate it.
>
> Thanks.
>
>
>


Anthony Procaccini

2004-03-26, 11:13 pm

On 2004-03-19 09:34:34 -0500, torch_bearer@hotmail.com said:
[color=darkred]
> (date("U") - date("U",$stored_date))/(60*60*24)
>
> This will first find the difference in seconds, then divide it by the
> amount of seconds in a day, of course you can use 86400 to save on the
> muliplication costs. This assumes that stored_date is a timestamp
> otherwise you'll need to make one with mktime.
>

For extra credit - can you find the number of *work* days (m-f) between
any two dates? For extra bonus credit, find the number of work days
skipping any holidays in between.

(An actual needed function in one of my database apps)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com