Hi there.

My web host is using MySQL version 4.0.22, and will not upgrade in a while. So my question is: Does anyone know of a different function I can use instead of MAKEDATE (which is available as of MySQL 4.1.1)?

Thanks in advance
/ jek

// Edit: changed maketime to makedate

    From the MySQL Manual

    mysql> SELECT MAKETIME(12,15,30);
            -> '12:15:30'
    

    So it's quite a simple one really so long as you don't need any inbuilt validation.

    mysql> SELECT CONCAT(12, ':', 15, ':', 30);
            -> '12:15:30'
    

    The index for MySQL's functions can be found here

      Thanks for your reply, but I see now that I have made a little (?) typo. The function I want to use is makeDATE.

      MAKEDATE(year,dayofyear)
      Returns a date, given year and day-of-year values.

      Sorry for the bother... / jek

        Perheps I don't need to use MAKEDATE at all, I'll try to explain what I'm trying to do instead.

        Here's an example table:

        +-----------+---------+--------+
        | startdate | enddate | string |
        +-----------+---------+--------+
        | 24-12     | 10-1    | test1  |
        +-----------+---------+--------+
        | 31-6      | 31-10   | test2  |
        +-----------+---------+--------+

        So, if the current date is between the 24:th december and the 10:th of january, any year, I want the query to select row 1 so I can echo the string containing "test1".

        Since this should work irrespective of what year it is, I cant figure out how to do the date-comparison.

        Thanks in advance
        / jek

          have a look at date_format available in mysql for a loooooong time.

            Thanks.

            I have tried using date_format, but I must be doing something wrong.

            Here's the query I have been tampering with:

            SELECT DATE_FORMAT('2005-startdate', '%Y-%m-%d') as start FROM testtable

            The table only contains one field: startdate, which is a text field containing month and day, like this: 01-01

            What am I doing wrong? I assume it has got something to do with my usage of the 'startdate' in the date_format function. But I just cant figure it out...

              Figured it out... Had to use concat()...

              So, for any future references:

              SELECT DATE_FORMAT(CONCAT('2005-'startdate, '%Y-%m-%d') as start FROM testtable
                Write a Reply...