Jump to content

Weekly Calculations


dtyson2000

Recommended Posts

Happy New Year, phpfreaks!

 

So I have a client that basically wants to see how many times THIS week (always in the present) his users are logging in. There's no real need to store any data. He just wants to see a current number for the current week he happens to be checking it in. So for a short time every week (starting at midnight Mondays) the counts will reset.

 

I haven't moved beyond the "thinking about it" phase yet and before I do I wanted to check with you to see if my thoughts make sense. Here's how I see it playing out:

 

1) obtain and set a variable for the current week of the year.

2) query database and count login dates (YYYY-MM-DD) that fall in that week per userid.

3) output user names and the number.

 

Do you see any real hurdles here with comparing the login dates to the week number? And do those three steps seem to be in line with what most of you would do?

 

Thanks for reading!

Link to comment
Share on other sites

I would not reset any counters, nor is there a need to. I would create a table containing the userID and the loginTime (DATETIME). Then everytime someone logs in, you insert a row to this table. You can easily query the table for a count by user where the loginTime is between the start and end time values for the week.

 

In my experience, about 15 minutes after you hand the first report to the boss, he will say; "you know what, I just want to see this at the end of the month" --- or something like that with some other date range. By logging the logins, you can provide just about any report he asks for. --- "Give me the counts by user of those that logged in on the weekends" (i.e. who are my hard workers?).

 

And, don't just give him each report he asks for. Tell him it will take a day or two, and then give it to him first thing in the morning. If you do it right away, people start expecting immediate results, and soon the world will learn that computer programmers are not really as vital as everyone thinks, because they will believe everything is easy, and you will ruin all of our lives. ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.