开发者

convert one specific query from text field to date for arithmetic functions

I have thoroughly searched but have been just as thoroughly confused at how to convert a returned SQL开发者_StackOverflow中文版 query into fields. I've found how to convert a whole column from text field into date but not a specific query. I'm not sure how to update, set, etc. I imported a CSV file of names and ates, and the query (in phpMyAdmin) that returns my desired text field is this:

SELECT meta_value FROM `drabble_postmeta` WHERE meta_key = 'date_paid'

This returns roughly 130 fields that I need to convert from a pure text field that is uniformly using MM/DD/YYYY (ie 11/2/2010) format to actually using the "date" field so I can then sort by date_paid.

One meta_value I get has a text field with "11/2/2010". meta_value is longtext. I don't know if I want to use the AS operator because I'll need to read other meta_value fields where the id of those columns == the id of where I found the date_paid.


Use the STR_TO_DATE function.

SELECT STR_TO_DATE(meta_value,'%m/%d/%Y') AS date_paid
    FROM `drabble_postmeta` 
    WHERE meta_key = 'date_paid'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜