473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calculate Days Worked

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
9 2163
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
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
..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
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
..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
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
"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
"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
..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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JP SIngh | last post by:
Hi All I need to calculate the number of working days between the two dates entered on an ASP page. I am not that great a coder in ASP and was wondering if someone can help. Basically the...
5
by: Hardy Wang | last post by:
Hi: Are there any algorithms I can use, that based on a given date and a culture code (different cultures may have different beginning of week), I can get first and last date of the current week?...
4
by: Sector 7G | last post by:
I'm working with a SQL query for a Human Resources database. Its intended purpose is to find all the paycheck records with a check date (prckhist.chkdate ) more recent than eleven days past the...
5
by: Beemer Biker | last post by:
I cant seem to get that date into any DateTime to make my calculation directly by subtracting "01-01-0000" from "now". After reading this:...
1
by: ndindi22 | last post by:
Can someone plz help me. I'm working on leave application, have to calculate number of leave days available, starting from Startdate to Enddate of a contract. Where an employee get 1 day leave...
3
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now...
4
by: shilpareddy2787 | last post by:
Hello, I have some total values, I want to calculate percenatge of these Total Values. I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period. ...
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
5
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.