How to change MySQL date format for database?

前端 未结 6 1651
执念已碎
执念已碎 2020-12-18 07:57

We are using a MySQL database with FileMaker. It appears that when FileMaker is reading the MySQL tables, it will only accept dates in the format of m/d/y.

Is there

6条回答
  •  自闭症患者
    2020-12-18 08:04

    The trick is not to change the format in MySQL (it isn't stored as a string anyway), but to specify the format you want when you query it.

    This can be achieved using something like this:

    SELECT date_format(mydatefield,'%m/%d/%Y') as mydatefield FROM mytable
    

    The official MySQL manual for this is here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

    By the way, off-topic but I feel I should mention it: I'd always recommend against using mm/dd/yyyy as a date format -- you'll confuse anyone from outside the US; virtually every other country in the world would normally use dd/mm/yyyy. But both those formats are ambiguous - what date do you mean when you say "12/05/2010"? probably a different one from me, but it's impossible to actually know which way round you intended.

    If you're intending to use the a date for display purposes, I'd always show the month as a word or abbreviation, as this removes any ambiguity. For input purposes, use a calendar control to avoid any possible confusion.

提交回复
热议问题