Format date in SELECT * query

后端 未结 5 1916
萌比男神i
萌比男神i 2020-12-17 20:25

Is it possible to format a date field in a SELECT * query? I want to get all of the columns from my table but need a different format from the date.

Something like:<

相关标签:
5条回答
  • 2020-12-17 20:33

    If you are writing application containing different timezones and formats better practice will be using UNIX timestamp stored in int(8) field, otherwise you can format date fields in queries.

    0 讨论(0)
  • 2020-12-17 20:36

    Use DATE_FORMAT:

    SELECT *, DATE_FORMAT(date, "%m-%d-%y") AS date FROM my_table;
    
    0 讨论(0)
  • 2020-12-17 20:37

    you can put name of column in back of date_format. like this :

    $rs = mysql_query("select  blablabla,DATE_FORMAT(name_column, '%d-%b-%y | %H:%i')name_column,DATE_FORMAT(name_column2, '%d-%b-%y | %H:%i')as name_column2 from db ORDER BY id DESC limit $offset,$rows");
    

    or you can put "as" yes, you must select one by one. its work !!!!

    0 讨论(0)
  • 2020-12-17 20:45

    I don't know what FORMATDATE is, but you can use DATE-FORMAT

    http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format

    0 讨论(0)
  • 2020-12-17 20:55
    select DATE_FORMAT(your_date_field_name,'%m-%d-%y') AS whatever FROM your_table_name_here;
    

    the result is something like this

    09-22-11

    as opposed to this

    2011-02-02 15:42:51

    0 讨论(0)
提交回复
热议问题