开发者

MySQL - Convert MM/DD/YY to Unix timestamp

开发者 https://www.devze.com 2023-01-10 13:41 出处:网络
Is there an easy (single query) way to do this?开发者_JAVA百科 I\'m reading those values from a column in a table and I think that the column itself is defined as a string (can\'t be helped, i\'m afr

Is there an easy (single query) way to do this?

开发者_JAVA百科

I'm reading those values from a column in a table and I think that the column itself is defined as a string (can't be helped, i'm afraid).


Use UNIX_TIMESTAMP;

SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19');

Update:

SELECT UNIX_TIMESTAMP(CAST(fieldName AS DATE));


SELECT UNIX_TIMESTAMP(STR_TO_DATE('08/05/10','%m/%d/%y'));


SELECT '12/31/10',
    STR_TO_DATE('12/31/10', '%m/%d/%y'),
    UNIX_TIMESTAMP(STR_TO_DATE('12/31/10', '%m/%d/%y'))

Both functions are covered here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

0

精彩评论

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