How to convert date(string type) into date(date time ) in oracle

此生再无相见时 提交于 2019-12-11 09:30:38

问题


I am stuck with a Oracle query. In my dashboard app, we have to show a summary graph for total of details lines basically. In one particular tab, we need the datetime in the details, but we group on the summary by date only.

How to convert date(string type) into date(date time ) in oracle. I am using select within select in other words nested select. Inner query returns string date time, and outer query unable to convert this to date time


回答1:


You would use the to_date function to convert a string to a date. For example

to_date( '2012-12-25 13:45:56', 'yyyy-mm-dd hh24:mi:ss' )

or

to_date( '12/25/98', 'MM/DD/RR' )

The format mask that you pass in as the second argument will depend on the format of the string. The set of valid format masks for the to_date function is in the documentation.




回答2:


You can use TO_DATE function.

For e.g:
If the input string in in the form 12/21/2012
You can try TO_DATE('12/21/2012', 'MM/DD/RRRR')

Check this link for more on variou formats: http://psoug.org/definition/TO_DATE.htm



来源:https://stackoverflow.com/questions/11461099/how-to-convert-datestring-type-into-datedate-time-in-oracle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!