6

Second rant today....

Can the class explain the following query and why I started wishing the author might suffer pain even after death?

$date1 = strtotime($_REQUEST['year1'].'-'.$_REQUEST['month1'].'-01');
$date2 = strtotime($_REQUEST['year2'].'-'.$_REQUEST['month2'].'-31');

MONTH(FROM_UNIXTIME($date1)) >= MONTH(FROM_UNIXTIME(timestampColum))
AND
MONTH(FROM_UNIXTIME($date2)) <= MONTH(FROM_UNIXTIME(timestampColum))

But... The drugs the author must have taken to write this must be frigging awesome.

Comments
  • 1
    I don't know what engine or language is it, so I don't know what's going on, other than he's trying to find out if the current date is between the beginning of a month in certain year and the end of another month in certain year, and that it seems like there is a lot of uses of the same calls that perhaps are redundant. What is it and what's the right way?
  • 1
    I understand it, I must be on the same drugs.
  • 0
    It is PHP and SQL.

    PHP is worse as in no validation and filtering user input. strtotime tries to parse the string given to timestamp, false on error (leading to 0 due to PHP typing, common error, validation of return value missing)

    The SQL is plain broken.

    Conversion / function usage leading to an expression instead of an constant makes index usage impossible.

    As u started, calls are redundant.

    But...

    MONTH just converts to integer, so if you have a range like
    '2016-08-01' to '2017-07-01'
    It basically does...

    08 >= MONTH(timestampColumn)
    AND
    07 <= MONTH(timestampColumn)

    ...
  • 2
    @IntrusionCM

    So it only compares months, at least that's what he meant. Why convert to timestamp, specially using strtotime on user input? This is wrong in so many ways 😀
  • 0
    Nope. It was implemented for Tine ranges. 😂

    Month Year ... Month Year.
  • 0
    Yes, but timestamp colum can actually have another year, I see no 'and year()='...
    Ahah, I'm glad I don't have to fix it
  • 0
    Yes.... That was the real big bug here....

    First I thought that it was meant for month to month of the same year, looked at the form and realized....

    Nope. Someone forgot something or had really no fucking clue what he was doing...

    But... Why the two dates, date1 and date2 then? Really confusing.
  • 0
    Period inside period?
    At least what he meant, not what he wrote.
    Day being 1 and 31 must be a clue, but I have no idea 😀
  • 1
    And even like this.... Adding for every year2 and month2 the day 31 is not even.... Valid...
  • 0
    @Baspar
    I didn't even noticed that 😀
    Just plain stupidity
Add Comment