By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,583 Members | 617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,583 IT Pros & Developers. It's quick & easy.

Calculate Days Worked

P: n/a
I have a set date in my MySQL database that records when a Sales Lead
is established and I echo that date as $row_rsLead['lead_date'];

I need to be able to calculate how many days that lead has existed.
$row_rsLead['lead_date']; outputs as 2007-06-14.

I have made numerous attempts to create a function that will calculate
the days between the lead_date and today's date, but have made
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.

Jun 14 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
howzit kirjoitti:
I have a set date in my MySQL database that records when a Sales Lead
is established and I echo that date as $row_rsLead['lead_date'];

I need to be able to calculate how many days that lead has existed.
$row_rsLead['lead_date']; outputs as 2007-06-14.

I have made numerous attempts to create a function that will calculate
the days between the lead_date and today's date, but have made
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.
http://dev.mysql.com/doc/refman/5.0/...ction_datediff

SELECT DATEDIFF(lead_date, NOW()) AS days

Or something like that. Next time RTFM before asking.

--
Ra*********@gmail.com

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

P: n/a
On Jun 14, 11:48 am, Rami Elomaa <rami.elo...@gmail.comwrote:
howzit kirjoitti:
I have a set date in my MySQL database that records when a Sales Lead
is established and I echo that date as $row_rsLead['lead_date'];
I need to be able to calculate how many days that lead has existed.
$row_rsLead['lead_date']; outputs as 2007-06-14.
I have made numerous attempts to create a function that will calculate
the days between the lead_date and today's date, but have made
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.

http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...

SELECT DATEDIFF(lead_date, NOW()) AS days

Or something like that. Next time RTFM before asking.

--
Rami.Elo...@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
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!

Jun 14 '07 #3

P: n/a
..oO(howzit)
>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.
You got an answer - does it work?

Micha
Jun 14 '07 #4

P: n/a
On Jun 14, 1:48 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(howzit)
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.

You got an answer - does it work?

Micha
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.

Jun 14 '07 #5

P: n/a
..oO(howzit)
>I don't want to edit my SELECT statement - as his answer would
suggest.
Why not? That would be the easiest and most reliable way.
>I need the SELECT statement to stay as it is.
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.
>I was hoping
for a function that would manipulate the one instance that I am
needing.
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
Jun 14 '07 #6

P: n/a
On Jun 14, 2:23 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(howzit)
I don't want to edit my SELECT statement - as his answer would
suggest.

Why not? That would be the easiest and most reliable way.
I need the SELECT statement to stay as it is.

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.
I was hoping
for a function that would manipulate the one instance that I am
needing.

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
Sound advice - I do appreciate your input. I will give it a shot -
and post back my progress. Thanks!

Jun 14 '07 #7

P: n/a
"howzit" <ji*******@gmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
>I have a set date in my MySQL database that records when a Sales Lead
is established and I echo that date as $row_rsLead['lead_date'];

I need to be able to calculate how many days that lead has existed.
$row_rsLead['lead_date']; outputs as 2007-06-14.

I have made numerous attempts to create a function that will calculate
the days between the lead_date and today's date, but have made
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.
Another method is to use INT for date values, which makes it a breeze to
calculate the difference between 2 dates.
Jun 15 '07 #8

P: n/a
"howzit" <ji*******@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
On Jun 14, 11:48 am, Rami Elomaa <rami.elo...@gmail.comwrote:
howzit kirjoitti:
I have a set date in my MySQL database that records when a Sales Lead
is established and I echo that date as $row_rsLead['lead_date'];
I need to be able to calculate how many days that lead has existed.
$row_rsLead['lead_date']; outputs as 2007-06-14.
I have made numerous attempts to create a function that will calculate
the days between the lead_date and today's date, but have made
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.
http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...

SELECT DATEDIFF(lead_date, NOW()) AS days

Or something like that. Next time RTFM before asking.

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.
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.
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!
What we have here is a failure to communicate. Nothing in your original post
indicated that you had in fact read the manual. You stated that you've made
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
time Read The Fine Manual before asking.

--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
Jun 15 '07 #9

P: n/a
..oO(keychain)
>Another method is to use INT for date values, which makes it a breeze to
calculate the difference between 2 dates.
Bad idea. What do you want to store there - days, hours, seconds? What
about daylight saving times and leap years?

Micha
Jun 15 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.