简体   繁体   English

将日期转换为字符串SQL

[英]Converting date to string SQL

I am building report in data warehouse which relay on comparing daily checks and payments for one of the restaurants. 我正在数据仓库中构建报告,该报告将继续比较其中一家餐馆的每日支票和付款。 I need to be able to filter data on date field however it needs to be compared with string that looks like US date format but is string so 我需要能够过滤日期字段上的数据,但是需要将其与看起来像美国日期格式但为字符串的字符串进行比较,因此

Select a.* from 
xx a, xy b
where 
a.payment_date = b.check_date

Format of a.payment_date is DD-MON-YY(date) and format of b.check_date is MM/DD/YYYY however it is a string. a.payment_date的格式为DD-MON-YY(date),b.check_date的格式为MM / DD / YYYY,但这是一个字符串。 Any pointers to most efficient ways of solving this problem greatly appreciated. 任何指向解决此问题的最有效方法的指针都将受到赞赏。

Convert check_date from string to date using TO_DATE() : 使用TO_DATE()check_datestring转换为date

SELECT a.*
FROM xx a, xy b
WHERE a.payment_date = TO_DATE(b.check_date, 'mm/dd/yyyy')

Or you can do the other way around, using TO_CHAR() . 或者,您也可以使用TO_CHAR()

将两个String日期都转换为真实日期( http://www.techonthenet.com/oracle/functions/to_date.php ),以便您可以按日期比较它们。

i think this may work fr you 我认为这可能对您有用

Select a.* from xx a, xy b where convert(datetime,a.payment_date) = convert(datetime,b.check_date) 从xx a,xy b中选择a。*,其中convert(datetime,a.payment_date)= convert(datetime,b.check_date)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM