简体   繁体   中英

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. Any pointers to most efficient ways of solving this problem greatly appreciated.

Convert check_date from string to date using TO_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() .

将两个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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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