(mysql) Selecting between two variables while matching a 3rd

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JoeyHogan
Forum Newbie
Posts: 1
Joined: Mon Feb 16, 2009 4:00 pm

(mysql) Selecting between two variables while matching a 3rd

Post by JoeyHogan »

Hi everyone,

I'm working modifying this small PHP time keeping program for a college I work for. This program keeps track of times that employees enter (it's not the time they enter it, as most people work away from the office, so they come by and punch multiple entries in at the same time).

I'm working on a function that will generate reports to show how many hours each person worked during a week. The dates are stored in one column (punch_date) in the format of 02.25, while the years are stored in another (punch_year), in the format 2009.

I am trying to figure out the query to use for this information:
-where punch_date is between 02.23 and 02.27 (including those two days)
-where punch_year is exactly 2009

I didn't write the original program (the guy working before me did). If I did, I would've made a different database design. But since the punches are already in this database, I have to keep it.....
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: (mysql) Selecting between two variables while matching a 3rd

Post by requinix »

If the date uses padded numbers (2 -> 02) in MM.DD format then you can use regular comparison operators.

Code: Select all

...WHERE punch_date BETWEEN "02.23" AND "02.27" AND punch_year="2009"
Post Reply