DATE function in Oracle - oracle

I recently came across sample code like this:
select TO_CHAR(DATE '2012-3-1', 'Day Month Year') from dual;
I understand the TO_CHAR, but I have never seen that use of DATE before, and can find no documentation relating to it. Can someone please explain how it works, and/or provide a link to some documentation?
Thanks,
Dan

You haven't searched far enough :-) Google Oracle DATE literal and find:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements003.htm#BABGIGCJ
An extract:
To specify a DATE value as a literal, you must use the Gregorian
calendar. You can specify an ANSI literal, as shown in this example:
DATE '1998-12-25'

here's the doc: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements003.htm#BABGIGCJ

Related

Oracle : Want to convert Substring to a useable, sortable date

1st Post go easy on me.
I'm using this Substring to pull part of a Field, this date I assume is probably non Standard (ddmmmyy) - how can I enhance this command so that I can use this a sortable Date Field, I'm guessing Cast but have no idea of Syntax etc ??
SELECT SUBSTR(Host_Name,-9) as Decom_Date
Output
DECOM_DATE
31Oct2018
31May2018
31May2018
31Mar2017
31Jul2018
TIA
This is exactly what the TO_DATE function is designed for:
SELECT TO_DATE(SUBSTR(Host_Name,-9), 'DDMonYYYY') as Decom_Date
It doesn't affect you here but bear in mind that oracle dates can only store down to a second precision. Also, if you have any rogue data in the table that can't be cant be parsed as a date you'll get "not a valid..." or "a nonnumeric was found where a numeric was expected".
Be mindful that your strings here are in English but parsing MON (3 letter month name) can be regionally contextual so this code might not work on a server with a different NLS; for example consider passing 'NLS_DATE_LANGUAGE = American' as the third argument to TO_DATE if you know your strings will always be English month names

Need help in Hive on date functions

I am doing functionality testing(need to write hive code while referring Scala code) in my project. I am having an issue with my date functions in my code. In Scala we have casted our date data type into string as changed its structure into ‘YYYYMM’, MY value inside my date column is like 201706(YYYYMM), which is not accepted in Hive (read that it accepts only YYYY-MM-DD).
My question is
1) How to change the YYYYMM to YYYY-MM-DD? I have tried casting to date and also UNIX_TIMESTAMP neither of them are working query is getting failed at the end.
2) We are also using filter.to_date (colm1,”YYYYMM”).between(add_months(to_date((colm2),”YYYYMM”),-27), add_months(to_date((colm2),”YYYYMM”),-2))) in our Scala code , How can I change that to HIVE? Unable to get any ideas
Thanks In advance…..
Regards,
M Sontosh Aditya
use
unix_timestamp(DATE_COLUMN, string pattern)
Further understanding please refer DateFuncitos

TO_TIMESTAMP_TZ Functionality

Any one have any idea how 'TO_TIMESTAMP_TZ' function works internally in oracle.
I want to know how it converts timestamp to timezone
The documentation is very handy for questions like this.
TO_TIMESTAMP_TZ converts a string into a timestamp with timezone information. It doesn't convert something that's already a timestamp into a timestamp with timezone information, without first having a conversion back into a string - which, as I'm sure you're aware, you should always do explicitly.

Oracle 10g Database Date Conversion to 'yyyy-iw' problems?

I'm not sure if this is a question or more of an exploration of a possible bug or a question about a better way to do handle this.
I have a rollup report that uses the
select column1id, column2date
from table1
where to_char(column2date,'yyyy-iw') = to_char(to_date('2012-12-31','yyyy-mm-dd'),'yyyy-iw')
The line: to_char(to_date('2012-12-31','yyyy-mm-dd'),'yyyy-iw') is converting to 2012-01, wrapping back to the beginning of the year.
Digging a bit further I find that the date 2012-12-31 is neither included in week: 2012-52 nor is it included in 2013-01, and 2012-53 doesn't return any data either... so I'm at a loss of what's going on here.
https://forums.oracle.com/forums/thread.jspa?threadID=995899
Ravi Kumar wrote: you need to use IYYY in format.
BluShadow wrote: ... When it calculates the YYYY and IW these are independant of each other so it won't reduce the YYYY output to [2013] just because you have included IW in the format mask. It looks at components of the mask and not the whole thing in combination.
select to_char(to_date('2012-12-31','yyyy-mm-dd'),'iyyy-iw') from dual;
returns 2013-01.
I think your WHERE clause should be:
where to_char(column2date,'iyyy-iw') = to_char(to_date('2012-12-31','yyyy-mm-dd'),'iyyy-iw')

seeking syntax for date in where clause in Jet OLEDB

I have a problem of using the where clause for limiting dates
I can't even get a simple statement like on "Feb 5 2010" to work,
e.g.,
select * from LineItems where DueDate = 2/5/2010;
I tried
"2/5/2010"
"2010/2/5"
"2010-2-5"
"2010-02-05"
2010-2-5
2010-02-05
...
but none worked.
Does anyone have an idea what the proper format for the date should
be? And should it be quoted?
Thank You!
This works for me in a Query
SELECT *
FROM Table1
where mydate = 2010/2/5
Writing a date like that is unambiguous; the other way round will depend on your locale settings.
Hey Guys, I did figured out that you must surround the date with a pair of #'s. Just leaving the date unsurrounded does not work for me. I figured this out by saving a "Filter" in the Data View of Access as query, then I looked at that query in SQL view.

Resources