# Calculate Days Worked

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
I have a set date in my MySQL database that records when a Sales Lead

I need to be able to calculate how many days that lead has existed.

I have made numerous attempts to create a function that will calculate
absolutely no headway.  I am either stuck working between differing
date formats or really strange numerical outputs.

If there is a script someone is willing to share or point me in a
direction that is good for a relative newcomer to PHP, I would be most
grateful.

Thanks folks.

## Re: Calculate Days Worked

howzit kirjoitti:

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_datediff

Or something like that. Next time RTFM before asking.

--
Rami.Elomaa@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

## Re: Calculate Days Worked

The reason I posted here (as stated above) was the solutions I have
read and researched were not working for me.  I was not asking to be
spoon fed - I asked for guidance and direction.

No need to insinuate I haven't RTFM.  If it is too much to help, keep
your bitter thoughts to yourself - everyone has to start somewhere you
dick!

## Re: Calculate Days Worked

.oO(howzit)

You got an answer - does it work?

Micha

## Re: Calculate Days Worked

I don't want to edit my SELECT statement - as his answer would
suggest.  I need the SELECT statement to stay as it is.  I was hoping
for a function that would manipulate the one instance that I am
needing.

## Re: Calculate Days Worked

.oO(howzit)

Why not? That would be the easiest and most reliable way.

Whenever possible you should let the database do all the dirty work.
It's very good at handling things like date calculations and does it
much more efficient than PHP.

In PHP you would have to turn the date into a Unix timestamp (strtotime)
and calculate the difference to the current date. Two things might
become an issue in some situations:

* daylight saving time
* Unix timestamp restrictions (1970-2038 on many systems)

There's also a calendar extension in PHP for doing Gregorian and Julian
date calculations, but this is not always available.

So, as said, let the DB do it if possible.

Micha

## Re: Calculate Days Worked

Sound advice - I do appreciate your input.  I will give it a shot -
and post back my progress.  Thanks!

## Re: Calculate Days Worked

Well you got both guidance and direction: a perfectly good solution and a
link to the correct manual page. I don't understand why you're upset.

What we have here is a failure to communicate. Nothing in your original post
numerous attempts to _create a function_, as in, not looking in the manual
or finding other solutions. That is why I suggested that you should next

--
Rami.Elomaa@gmail.com

"Good tea. Nice house." -- Worf

## Re: Calculate Days Worked

Another method is to use INT for date values, which makes it a breeze to
calculate the difference between 2 dates.

## Re: Calculate Days Worked

.oO(keychain)

Bad idea. What do you want to store there - days, hours, seconds? What
about daylight saving times and leap years?

Micha