473,385 Members | 1,324 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,385 software developers and data experts.

Novice looking for advice (date comparison).

Mo
After a little PHP education, my first project (to get my feet wet) is
making an employee time-tracking program for our small business.

*** ANY SUGGESTION, THOUGHTS, OR ADVICE WOULD BE WARMLY WELCOMED ***

I'm in my planning stage, and here's my hurdle:
On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?

One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.
This seems like it could work well, but I would like to get a review
from those with more experience.

Lastly, if this Calendar table is a good way to go, does anyone have a
table like this wich they coud just provide a SQL export of, or any
advice on how to go about creating one (preferrably with day and date
values).

~Mo

(NOTE: While a table dump would get me going quicker, I'd prefer to
learn how to do it.)
Jun 2 '08 #1
9 1702
On Wed, 07 May 2008 17:54:41 +0200, Mo <Me***********@gmail.comwrote:
After a little PHP education, my first project (to get my feet wet) is
making an employee time-tracking program for our small business.

*** ANY SUGGESTION, THOUGHTS, OR ADVICE WOULD BE WARMLY WELCOMED ***

I'm in my planning stage, and here's my hurdle:
On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?

One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.
This seems like it could work well, but I would like to get a review
from those with more experience.

Lastly, if this Calendar table is a good way to go, does anyone have a
table like this wich they coud just provide a SQL export of, or any
advice on how to go about creating one (preferrably with day and date
values).
It would be the way to go (and the answer is better asked in
comp.databases.mysql), but a 'calender' table with just the numbers from
1-366 for days of the year, and left joining against that would suffice.
You don't have to have _all_ possible dates (which will probably end up
causing some other developer headaches as soon as the dates 'run out'.
--
Rik Wasmus
Jun 2 '08 #2
Mo
On May 7, 8:09*am, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Wed, 07 May 2008 17:54:41 +0200, Mo <Mehile.Orl...@gmail.comwrote:
After a little PHP education, my first project (to get my feet wet) is
making an employee time-tracking program for our small business.
*** ANY SUGGESTION, THOUGHTS, OR ADVICE WOULD BE WARMLY WELCOMED ***
I'm in my planning stage, and here's my hurdle:
On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?
One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.
This seems like it could work well, but I would like to get a review
from those with more experience.
Lastly, if this Calendar table is a good way to go, does anyone have a
table like this wich they coud just provide a SQL export of, *or any
advice on how to go about creating one (preferrably with day and date
values).

It would be the way to go (and the answer is better asked in *
comp.databases.mysql), but a 'calender' table with just the numbers from *
1-366 for days of the year, and left joining against that would suffice. *
You don't have to have _all_ possible dates (which will probably end up *
causing some other developer headaches as soon as the dates 'run out'.
--
Rik Wasmus- Hide quoted text -

- Show quoted text -
Thank you, I'll post to that group.

In learning how to do it, I was hoping to then create a form in which
I could punch in a date range (or just an ending date) and have some
sql further populate the Calendar table. I could just run that at the
turn of our fiscal year or something.
This kinda seemed like it would help avert disaster.

Thanks again.
~Mo
Jun 2 '08 #3
Mo escribió:
On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?

One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.
That's crazy. You'd be overpopulating your DB with dumb data that will
need forever maintenance.

It's way easier than that:

1. Fetch the available DB data into a PHP array
2. In PHP, loop through the range of dates. For each date:
- If there is data, print it
- If not, print 'Absent'

SELECT UNIX_TIMESTAMP(DATE) AS DATE, USER, BLAH
FROM PUNCH_TIMES
WHERE .....

As about looping:

$from = mktime(0, 0, 0, 1, 1, 2008);
$to = time();

for($i=$from; $<=$to; $i=strtotime('+1 day', $i)){
echo date('d/m/Y', $i) . ":\n";
if( isset($punch_data[$employee][$i]) ){
...
}else{
echo "Absent\n";
}
/*...*/
}
I'm missing several steps but I hope you see the idea.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 2 '08 #4
Álvaro G. Vicario wrote:
Mo escribió:
>On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?

One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.

That's crazy. You'd be overpopulating your DB with dumb data that will
need forever maintenance.

It's way easier than that:

1. Fetch the available DB data into a PHP array
2. In PHP, loop through the range of dates. For each date:
- If there is data, print it
- If not, print 'Absent'

SELECT UNIX_TIMESTAMP(DATE) AS DATE, USER, BLAH
FROM PUNCH_TIMES
WHERE .....

As about looping:

$from = mktime(0, 0, 0, 1, 1, 2008);
$to = time();

for($i=$from; $<=$to; $i=strtotime('+1 day', $i)){
echo date('d/m/Y', $i) . ":\n";
if( isset($punch_data[$employee][$i]) ){
...
}else{
echo "Absent\n";
}
/*...*/
}
I'm missing several steps but I hope you see the idea.

No, it's not crazy, and it's quite commonly done - I've seen it in a
bunch of different RDBMS's.

Doing it like this and everything can be handled in one SQL SELECT
statement. Not only will it be faster, but there's much less code to
maintain.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #5
Mo
On May 8, 5:03*am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Álvaro G. Vicario wrote:
Mo escribió:
On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?
One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.
That's crazy. You'd be overpopulating your DB with dumb data that will
need forever maintenance.
It's way easier than that:
1. Fetch the available DB data into a PHP array
2. In PHP, loop through the range of dates. For each date:
* * - If there is data, print it
* * - If not, print 'Absent'
SELECT UNIX_TIMESTAMP(DATE) AS DATE, USER, BLAH
FROM PUNCH_TIMES
WHERE .....
As about looping:
$from = mktime(0, 0, 0, 1, 1, 2008);
$to = time();
for($i=$from; $<=$to; $i=strtotime('+1 day', $i)){
* * echo date('d/m/Y', $i) . ":\n";
* * if( isset($punch_data[$employee][$i]) ){
* * * * ...
* * }else{
* * * * echo "Absent\n";
* * }
* * /*...*/
}
I'm missing several steps but I hope you see the idea.

No, it's not crazy, and it's quite commonly done - I've seen it in a
bunch of different RDBMS's.

Doing it like this and everything can be handled in one SQL SELECT
statement. *Not only will it be faster, but there's much less code to
maintain.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
Of course I always preffer speed of execution and simplicity of code,
but I've just come up with one concerne ...
Would we be able to generate a report (without errors) across a
NewYear date if we were numbering the days 1-366?

We have one group of our employees which gets paid on every 15th, so
even in our regular reports, we would encounter this at least once per
year.

~Mo
Jun 2 '08 #6
Mo wrote:
On May 8, 5:03 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Álvaro G. Vicario wrote:
>>Mo escribió:
On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?
One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.
That's crazy. You'd be overpopulating your DB with dumb data that will
need forever maintenance.
It's way easier than that:
1. Fetch the available DB data into a PHP array
2. In PHP, loop through the range of dates. For each date:
- If there is data, print it
- If not, print 'Absent'
SELECT UNIX_TIMESTAMP(DATE) AS DATE, USER, BLAH
FROM PUNCH_TIMES
WHERE .....
As about looping:
$from = mktime(0, 0, 0, 1, 1, 2008);
$to = time();
for($i=$from; $<=$to; $i=strtotime('+1 day', $i)){
echo date('d/m/Y', $i) . ":\n";
if( isset($punch_data[$employee][$i]) ){
...
}else{
echo "Absent\n";
}
/*...*/
}
I'm missing several steps but I hope you see the idea.
No, it's not crazy, and it's quite commonly done - I've seen it in a
bunch of different RDBMS's.

Doing it like this and everything can be handled in one SQL SELECT
statement. Not only will it be faster, but there's much less code to
maintain.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

Of course I always preffer speed of execution and simplicity of code,
but I've just come up with one concerne ...
Would we be able to generate a report (without errors) across a
NewYear date if we were numbering the days 1-366?

We have one group of our employees which gets paid on every 15th, so
even in our regular reports, we would encounter this at least once per
year.

~Mo
No, you just need to check to see if this is a leap year or not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #7
Mo
On May 9, 10:03*am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mo wrote:
On May 8, 5:03 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Álvaro G. Vicario wrote:
Mo escribió:
On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?
One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.
That's crazy. You'd be overpopulating your DB with dumb data that will
need forever maintenance.
It's way easier than that:
1. Fetch the available DB data into a PHP array
2. In PHP, loop through the range of dates. For each date:
* * - If there is data, print it
* * - If not, print 'Absent'
SELECT UNIX_TIMESTAMP(DATE) AS DATE, USER, BLAH
FROM PUNCH_TIMES
WHERE .....
As about looping:
$from = mktime(0, 0, 0, 1, 1, 2008);
$to = time();
for($i=$from; $<=$to; $i=strtotime('+1 day', $i)){
* * echo date('d/m/Y', $i) . ":\n";
* * if( isset($punch_data[$employee][$i]) ){
* * * * ...
* * }else{
* * * * echo "Absent\n";
* * }
* * /*...*/
}
I'm missing several steps but I hope you see the idea.
No, it's not crazy, and it's quite commonly done - I've seen it in a
bunch of different RDBMS's.
Doing it like this and everything can be handled in one SQL SELECT
statement. *Not only will it be faster, but there's much less code to
maintain.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
Of course I always preffer speed of execution and simplicity of code,
but I've just come up with one concerne ...
Would we be able to generate a report (without errors) across a
NewYear date if we were numbering the days 1-366?
We have one group of our employees which gets paid on every 15th, so
even in our regular reports, we would encounter this at least once per
year.
~Mo

No, you just need to check to see if this is a leap year or not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
So, if I generate a report this year (2008) for the 12/16/07 - 1/15/08
date range, how do I make it identify the day numbers from December as
being from a prior year?
If I'm understanding all this correctly, our range of day numbers
would be 349-15.
Would I just have to use some function to extract the year value from
the date range provided by the user via the form?

~Mo
Jun 2 '08 #8
Mo wrote:
On May 9, 10:03 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Mo wrote:
>>On May 8, 5:03 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Álvaro G. Vicario wrote:
Mo escribió:
>On the time report, we want to see EVERY date under each employee, and
>the string "Absent" for the dates on which the user has no punch
>times. (It would also be nice to include day-names on the report.)
>Obviously the Time table will only have entries for when people
>actually clock in/out, so how do I get the other dates to show on the
>report?
>Any suggestions?
>One guy here suggested just adding a table (to the MySQL DB ) which
>includes every date from here to ...., then just do an outer join.
That's crazy. You'd be overpopulating your DB with dumb data that will
need forever maintenance.
It's way easier than that:
1. Fetch the available DB data into a PHP array
2. In PHP, loop through the range of dates. For each date:
- If there is data, print it
- If not, print 'Absent'
SELECT UNIX_TIMESTAMP(DATE) AS DATE, USER, BLAH
FROM PUNCH_TIMES
WHERE .....
As about looping:
$from = mktime(0, 0, 0, 1, 1, 2008);
$to = time();
for($i=$from; $<=$to; $i=strtotime('+1 day', $i)){
echo date('d/m/Y', $i) . ":\n";
if( isset($punch_data[$employee][$i]) ){
...
}else{
echo "Absent\n";
}
/*...*/
}
I'm missing several steps but I hope you see the idea.
No, it's not crazy, and it's quite commonly done - I've seen it in a
bunch of different RDBMS's.
Doing it like this and everything can be handled in one SQL SELECT
statement. Not only will it be faster, but there's much less code to
maintain.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
Of course I always preffer speed of execution and simplicity of code,
but I've just come up with one concerne ...
Would we be able to generate a report (without errors) across a
NewYear date if we were numbering the days 1-366?
We have one group of our employees which gets paid on every 15th, so
even in our regular reports, we would encounter this at least once per
year.
~Mo
No, you just need to check to see if this is a leap year or not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

So, if I generate a report this year (2008) for the 12/16/07 - 1/15/08
date range, how do I make it identify the day numbers from December as
being from a prior year?
If I'm understanding all this correctly, our range of day numbers
would be 349-15.
Would I just have to use some function to extract the year value from
the date range provided by the user via the form?

~Mo
At this point you're getting farther out of the PHP range and more into
MySQL. You need to be asking this in comp.databases.mysql.

It can be done - but this isn't a PHP problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #9
Mo
On May 9, 4:52*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mo wrote:
On May 9, 10:03 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mo wrote:
On May 8, 5:03 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Álvaro G. Vicario wrote:
Mo escribió:
On the time report, we want to see EVERY date under each employee, and
the string "Absent" for the dates on which the user has no punch
times. (It would also be nice to include day-names on the report.)
Obviously the Time table will only have entries for when people
actually clock in/out, so how do I get the other dates to show on the
report?
Any suggestions?
One guy here suggested just adding a table (to the MySQL DB ) which
includes every date from here to ...., then just do an outer join.
That's crazy. You'd be overpopulating your DB with dumb data that will
need forever maintenance.
It's way easier than that:
1. Fetch the available DB data into a PHP array
2. In PHP, loop through the range of dates. For each date:
* * - If there is data, print it
* * - If not, print 'Absent'
SELECT UNIX_TIMESTAMP(DATE) AS DATE, USER, BLAH
FROM PUNCH_TIMES
WHERE .....
As about looping:
$from = mktime(0, 0, 0, 1, 1, 2008);
$to = time();
for($i=$from; $<=$to; $i=strtotime('+1 day', $i)){
* * echo date('d/m/Y', $i) . ":\n";
* * if( isset($punch_data[$employee][$i]) ){
* * * * ...
* * }else{
* * * * echo "Absent\n";
* * }
* * /*...*/
}
I'm missing several steps but I hope you see the idea.
No, it's not crazy, and it's quite commonly done - I've seen it in a
bunch of different RDBMS's.
Doing it like this and everything can be handled in one SQL SELECT
statement. *Not only will it be faster, but there's much less code to
maintain.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
Of course I always preffer speed of execution and simplicity of code,
but I've just come up with one concerne ...
Would we be able to generate a report (without errors) across a
NewYear date if we were numbering the days 1-366?
We have one group of our employees which gets paid on every 15th, so
even in our regular reports, we would encounter this at least once per
year.
~Mo
No, you just need to check to see if this is a leap year or not.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
So, if I generate a report this year (2008) for the 12/16/07 - 1/15/08
date range, how do I make it identify the day numbers from December as
being from a prior year?
If I'm understanding all this correctly, our range of day numbers
would be 349-15.
Would I just have to use some function to extract the year value from
the date range provided by the user via the form?
~Mo

At this point you're getting farther out of the PHP range and more into
MySQL. *You need to be asking this in comp.databases.mysql.

It can be done - but this isn't a PHP problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
cool, thanks
Jun 2 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: RelaxoRy | last post by:
So I like this girl and.. harrrranyway, I have birth dates in a table stored as 11/07/1982 or 7/5/1974 etc. Now there are 7150 records and I cannot really alter the date format to conform...
2
by: Scott Knapp | last post by:
Good Day - I have a form which sets the current date, as follows: <script type="text/javascript"> xx=new Date() dd=xx.getDate() mm=xx.getMonth()+1 yy=xx.getYear() mmddyy=mm+"/"+dd+"/"+yy...
2
by: bole2cant | last post by:
I just received my free VB.NET package from MS, and can't figure out how to Save As. I loaded a sample program and made a bunch of changes to it and wanted to save it without overwriting the...
3
by: Tiya | last post by:
Hi there !!! I would like to know how to compare dates in javascript. var sdate = new Date(theform.SubmissionDate.value); var odate = new Date(theform.StartDate.value); var todaysdate = new...
4
by: tony | last post by:
I'm designing a survey form page that will be fairly complex and am becoming confident enough with PHP now to tackle most things. (Thanks to everyone here who has helped) Before I go too far...
25
by: gordon | last post by:
I aksed a few days ago about static methods and got some good answers that were really useful. Now I am not sure if about the use of static on members (variables) and classes. Can someone...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
3
by: AMDRIT | last post by:
I am working with ObservableCollection and looking to implement sorting. I ran across code from Paul Stovell and he has: In the collection class the derives from ObservableCollection public...
4
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.