The context is that there is an existing application in our product which generates and sends the EPOCH number to an existing oracle procedure & vice versa. It works in that procedure using something like this
SELECT UTC_TO_DATE (1463533832) FROM DUAL
SELECT date_to_utc(creation_date) FROM mytable
When I tried these queries it does work for me as well with Oracle 10g server (and oracle sql developer 4.x if that matters).
In the existing procedure the requirement was to save the value as date itself (time component was irrelevant), however in the new requirement I have to convert unix EPOCH value to datetime (at the hours/mins/seconds level, or better in a specific format such as dd-MMM-yyyy hh:mm:ss) in an oracle query. Strangely I am unable to find any documentation around the UTC_TO_DATE and DATE_TO_UTC functions with Google. I have looked around at all different questions on stackoverflow, but most of them are specific to programming languages such as php, java etc.
Bottom line, how to convert EPOCH to that level of time using these functions (or any other functions) in Oracle query? Additionally are those functions I am referring could be custom or specific somewhere, as I don't see any documentation or reference to this.
Another option is to use an interval type:
It has this advantage that milliseconds won't be cut.
If your epoch time is stored as an integer..... And you desire the conversion to Oracle date format.
Step 1--> Add your epoch date (1462086000) to standard 01-jan-1970. 86400 is seconds in a 24 hour period.
Step 2--> Convert it to a CHAR . This is needed for formatting before additional functions can be applied.
Step 3--> Now onto Timestamp conversion
Step 4--> Now need the TimeZone, usage of UTC
Step 5--> If your timezone need is PST
Step 6--> Format the PST Timezone timestamp.
Step 7--> And finally, if your column is date datatype
To convert from milliseconds from epoch (assume epoch is Jan 1st 1970):
11/30/2011 5:00:00 AM
To convert that date back to milliseconds:
1322629200000
If its seconds instead of milliseconds, just omit the 1000 part of the equation:
Hope that helps.
I thought somebody would be interested in seeing an Oracle function version of this:
I had a bunch of records I needed dates for so I updated my table with:
where a is a number between 1 and 10,000,000.
Here it is for both UTC/GMT and EST;