Jump to content


Date range help?

  • Please log in to reply
1 reply to this topic

#1 Moron

  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 11 August 2006 - 07:03 PM

I'm working on an employee leave system. My script is pulling all leave incidents, but I only want it to pull the last six months.
Here's the code where it plugs the leave items:

echo $RESULT['Lmo']; 
echo "/";
echo $RESULT['Lda'];
echo "/";
echo $RESULT['LYR'];

(Leave month, Leave day, Leave year).

I also set a variable called....

..which combines the above three into "08112006" format.

...and another one called $pastdate which pulls the date on today's date six months ago.

If I use...
WHERE ('$currentdate' >= '$pastdate')

or IF


or anything else I've tried, it either bombs or returns nothing.

I want to show records from six months ago through the present.


#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,022 posts

Posted 11 August 2006 - 07:58 PM

To compare dates you need the date elements in Y M D sequence.

MySQL and other DBMS have things called DATE fields. If you use these you have dozens of date functions at your disposal. IF you invent other ways to store dates then you have to invent ways to do the calculations them.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users