相当于MySQL的ISDATE() [英] ISDATE() equivalent for MySQL

查看:408
本文介绍了相当于MySQL的ISDATE()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一行用于SQL Server的代码,其日期列为"YYYYMMDD",其中DD为00,并将00转换为01,以便它与datetime一起使用.我希望能够使用MySQL

I have a line of code for SQL server which takes a date listed as "YYYYMMDD" where the DD is 00 and converts the 00 to 01 so that it works with datetime. I would like to be able to use MySQL for it

适用于SQL Server的当前代码:

the current code which works for SQL server:

INSERT patentdb.Citation(PatentNo, Citation, CitedBy, CitationDate)
SELECT PatentNo, citation, WhoCitedThis, dt 
FROM 
(
  SELECT PatentNo, Citation, WhoCitedThis, dt = CASE
    WHEN CitationDate LIKE '%00' THEN INSERT (CitationDate, 8, 1, '1') 
    ELSE CitationDate 
  END 
  FROM patentdb.CitationSource
) AS x
WHERE ISDATE(dt) = 1;

但是isdate在MySQL中无效,该怎么解决?

but isdate is not valid in MySQL, what can I do to fix this?

推荐答案

您可以尝试使用

You can try using the STR_TO_DATE function. It returns null if the expression is not date, time, or datetime.

WHERE STR_TO_DATE(dt, '%d,%m,%Y') IS NOT NULL

这篇关于相当于MySQL的ISDATE()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆