I'd like to store both my date and time in the same table (a datetime table)

When I query the database, I'd like to break apart these to get month, day, year, hour, etc in separate variables

Here's what I have done:

$select = mysql_query("SELECT *,DATE_FORMAT(date, '%M') AS month,DATE_FORMAT(date, '%e') AS day,DATE_FORMAT(date, '%Y') AS year FROM mytable WHERE id = '$_GET[id]' LIMIT 1") or die(showerror());

Is there any easier way to break everything apart other than having like 6 different date_format things? Maybe somehow just select the date once, then format it in PHP?

    Doing this with PHP would be simpler. Though I stringly suggest you not do this. Leave it as one field as there are many date/time functions in mysql that support queries based on that type of field...

      Store your date as a unix timestamp.

      linky

        you can do DATE_FORMAT(date, '%Y-%M-%e') and then use explode in php

        or you try something like

        SELECT
          MONTHNAME(date),
          DAYOFMONTH(date),
          YEAR(date)
          Write a Reply...