Unix Timestamp to date
hi,
I am using SQL developer to query an oracle 8 Database and
I need to convert a unix timestamp to a specific date time format - YYYYMMDD HH24:MI:SS
I am currently using
,to_date('19700101 00:00:01','YYYYMMDD HH24:MI:SS')+sh.order_date/86400
but this just returns the date in the format DD-MMM-YY
Hi,
Welcome to the forum!
What is a unix timestamp?
If it's the number of seconds since mdinight on January 1, 1970, then you can convert that to a DATE like this:
DATE '1970-01-01' + ( unix_timestamp
/ (24 * 60 * 60)
)To display any DATE in a specific format, use TO_CHAR:
TO_CHAR ( DATE '1970-01-01' + ( unix_timestamp
/ (24 * 60 * 60)
, 'YYYYMMDD HH24:MI:SS'
)
Similar Messages
-
Converting unix timestamp to date after Daylight Saving Time change
Hello,
in one of the products we use the internal scheduler stores dates (and times) in an Unix-like format, that is seconds since 1st of January 1970. We have used this SQL to extract the actual date:
TO_CHAR(t.next_fire_time/(24*60*60*1000) +to_date('19700101020000','yyyymmddhh24miss'),'yyyymmddhh24miss')
Everything worked fine until the time has changed this weekend from UTC+2 to UTC+1 (we are located in Eastern Europe). Since then the query above returns one hour later than it should.
I.e. timestamp *1320067800000* is returned as *20111031153000* even thought correct is (and the actual time the event was scheduled) *31-OCT-11 02.30.16.000000 PM*
I found queries like this on different forums and no one seems to worry much about the daylight savings. Is this a configuration issue in the DB or is it a bug in our code?
I tried selecting the SESSIONTIMEZONE and DBTIMEZONE and both were +1.
Any help appreciated.Your problem is hard-coded 2hour offset:
to_date('19700101<font size=5 color=red>02</font>0000','yyyymmddhh24miss')You need to calculate current offset to adjust it to current DST situation:
with sample_table as (
select date '1970-01-01' + 1320067800000 / 1000 / 3600 / 24 dt_utc from dual
select dt_utc,
dt_utc +
extract(
timezone_hour
from
from_tz(cast(dt_utc as timestamp),'utc') at time zone 'Europe/Prague'
) / 24 dt_prague,
extract(
timezone_hour
from
from_tz(cast(dt_utc as timestamp),'utc') at time zone 'Europe/Prague'
) tz_offset
from sample_table
DT_UTC DT_PRAGUE TZ_OFFSET
2011-10-31 13:30:00 2011-10-31 14:30:00 1
SQL> SY. -
As I opened the places.sqlite with an sqlite-editor I found out that firefox saves the last_visit_date via a timestamp which is 16 digits long. I realized that the first 10 digits are similar to the corresponding unix-timestamp but not equal. So.. how can i convert the firefox-timestamp into a normal date? Or into the corresponding unix-timestamp?
Write a bash script or 'C' program to change the date format and then use the sql update function to receive the stdio output 'where date_field='embeded date value'.
-
Getting a date as a unix timestamp
Hello everyone,
is the long that is returned by the getTime() method in the date class supposed to be the same as a unix timestamp?
Below I have a time from yesterday, but when i compare this with System.currentTimeMillis(), the currentTime has a smaller timestamp
code]SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-kk:mm:ss");
long expiryDate=0;
try{
Date d = sdf.parse("11-11-2006-19:07:50");
expiryDate = d.getTime(); results in 1163358470000
catch(ParseException pe){
pe.printStackTrace();
yesterdays time is 1163358470000
current time is 1163355193562 // smaller number
Whats going on?sorry, here it is again
is the long that is returned by the getTime() method in the date class supposed to be the same as a unix timestamp?
Below I have a time from yesterday, but when i compare this with System.currentTimeMillis(), the currentTime has a smaller timestamp
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-kk:mm:ss");
long expiryDate=0;
try{
Date d = sdf.parse("11-11-2006-19:07:50");
expiryDate = d.getTime(); results in 1163358470000
catch(ParseException pe){
pe.printStackTrace();
}yesterdays time is 1163358470000
current time is 1163355193562 // smaller number
Whats going on? -
Select entries between two dates by converting Unix timestamp in Oracle Dat
Hi,
I need to select the entries between two dates from an Oracle db. The Oracle db has a column with Unix timestamps. I use the following querry, but it doesnt seem to be working as desired.
select count(*) from reporter_status where to_char(FIRSTOCCURRENCE, 'mm-dd-yy') between ('08-07-06') and ('08-08-06');
FIRSTOCCURRENCE has the Unix timestamps.
Could anyone help me out with this. Thank you for your help.Assuming that it is actually a UNIX timestamp, then it is the number of seconds since Jan 1, 1970, so you need something like:
SELECT COUNT(*)
FROM reporter_status
WHERE TO_DATE('01-Jan-1970', 'dd-mon-yyyy') + (firstoccurrence/24/60/60)
BETWEEN TO_DATE('08-07-2006', 'mm-dd-yyyy') AND
TO_DATE('08-08-2006, 'mm-dd-yyyy');Did Y2K not teach us anything? Use 4 digit years.
John -
Unix timestamp conversion to human readable representation ...
Hi,
I map unix timestamps from MaxDB to the controller context of Web Dynpro and display the results in a table. Is there a smart way to convert the timestamps to human readable date and time? Maybe some way to manipulate the table values with a function before they are written ..?
For now, I create a new node in the context and manually set each value with the according date/time representation ... but thats pretty cumbersome.
Thank you very much for your help!
Cheers,
borisHi Boris,
Check http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
Date currentTime_1 = new Date(longUnixTimestamp);
String dateString = formatter.format(currentTime_1);
I would suggest you to create a calculated attribute under the same node as initial timestamp value and return a result of SimpleDateFormat.format().
Best regards, Maksim Rashchynski. -
Unix timestamp to Oracle timestamp conversion
Hi all,
I am trying to convert the UNIX timestamp to ORACLE timestamp .
I have done like this upto now.
CREATE OR REPLCACE FUNCTION unixts_to_oraclets(unixtimestamp IN INTEGER)
RETURN DATE IS
result DATE;
BEGIN
result := TO_DATE('1970-01-01', 'YYYY-MM-DD') + numtodsinterval(unixtimestamp, 'SECOND');
return(result);
end unixts_to_oraclets;
now i have run this query
SQL> select unixts_to_oraclets(1139291114) as TS from dual;
TS
07-FEB-06
now i need the ouput to like this 07-FEB-06 01:10:12
for that i have done like this:
DECLARE
v_date DATE;
res_date DATE;
BEGIN
SELECT from_uts(1139291114)INTO v_date FROM dual;
SELECT TO_TIMESTAMP(v_date,'DD-MON-RRHH24.MI.SS.FF') INTO res_date FROM dual;
DBMS_OUTPUT.PUT_LINE(res_date);
END;
but the output is :
SQL> /
07-FEB-06
PL/SQL procedure successfully completed.
why is that it is not printing 07-FEB-06 01:10:12 ?
how should i moodify the code to get the desired output.
please help me i this regard
Trinath Somanchi,
Hyderabad.SQL> exec dbms_output.put_line(sysdate);
07-FEB-06
PL/SQL procedure successfully completed.
SQL> exec dbms_output.put_line(to_char(sysdate, 'DD-MM-YYYY HH24:MI:SS'));
07-02-2006 02:48:35
PL/SQL procedure successfully completed.
SQL> alter session set nls_date_format='DD-MM-YYYY HH24:MI:SS';
Session altered.
SQL> exec dbms_output.put_line(sysdate);
07-02-2006 02:49:03
PL/SQL procedure successfully completed. -
Unix timestamp / epoch conversion in IQ
Hello,
I searched the community as well as some other historical locations, but couldn't find any discussions on this.
In several of the projects I am working with, there is a source datetime field that always comes in as a unix timestamp (i.e. seconds since the epoch). The question I regularly get is, can we load this into IQ and have it converted during load from the integer into an IQ datetime column.
I have my own suggestions for how to solve this already, but rather than influence the creative (or resolute) mind, I thought I'd put it out to the community to see how you have/would solve this issue?
Thoughts??
Thank you,
-Joe Love
SAP Mobile Services and Consumer InsightsNone that I am aware of during the LOAD TABLE event. You can always load it and post process the data, but that's gets ugly and requires you to carry an extra column in your table. My typical approach is to have the data converted before loading into IQ. If the data is being touched by a streaming engine, ETL tool, or replication, you can do it all inline with those tools and a little coding. For 3rd party tools, I would have them change their code to generate readable date/time stamps. That or pre-process the data with something like sed or awk.
Mark -
Sometime ago I produced a php and SQL jobsite. Users apply
for jobs and the date they apply is converted into a unix timestamp
and inserted into the SQL as an integer.
I am now using coldfusion increasingly more, and am wanting
to display the results above using a cfgrid.
Although I have found similar posts in this forum I still
have two oustanding queries:
1) How do I catch the date for each row before the cfgrid
displays it
2) How to convert unix timestamp using coldfusionchilliroom wrote:
>
quote:
format it via the db is probably the cheapest.
> I am still unsure how to catch the date for each row
before the cfgrd grabs it.
what db? does it have this functionality? for sql server
something like should
work (but again watch for overflow):
SELECT
dateAdd(second,yourUnixEpochOffsetDataColumn,'1-jan-1970') as
aDate,....
FROM yourTable
> How can I extract this value to then feed into
"yourUnixEpochOffsetData".
if your db can't handle this, here's one way using cf (but
the db is cheaper).
do your normal cfquery then:
- convert the unix epoch offsets to datetimes:
unixEpoch=createDate(1970,1,1);
newDates=arrayNew(1);
for (i=1; i LTE yourRegularcfQuery.recordCount;i=i+1) {
newDates
=dateAdd("s",yourRegularcfQuery.yourUnixEpochOffsetDataColumn,unixEpoch);
depending on your needs, you might also want to dateFormat
the results of the
dataAdd:
newDates
=dateFormat(dateAdd("s",yourRegularcfQuery.yourUnixEpochOffsetDataColumn,unixEpoch));
- add a column to your cfquery & fill with those
converted dates,
queryAddColumn(yourRegularcfQuery,"aDate","date",newDates); -
Hello
How do I convert UNIX timestamp to Oracle
Thanks
Sameerhi,
Write a Shell script which will pass the date to the procedure as a Parameter.
Example.
dt=`date`
echo $dt
sqlplus /nolog < scott/tiger 2>/dev/null <!EOF
begin
convertDate('$dt');
end;
!EOFThe Procedure.
Create Or replace function convertDate(dt in Varchar2) return Date
As
convertDt Date;
Begin
-- Assuming that the Dt is 'Mon 3 Sep 2001 14:00:45'
select to_date(dt, 'Dy DD Mon YYYY hh24:MI:SS') into convertDt from dual;
return convertDt;
End;Since i dont have a Unix Mac u will have to tweak the Shell Script on the Redirection Symbols.
Oracle Does not support Timezones ... If u need to Incorportae TZ then pls look into a Java Solutiion.
Hope this helps.
Regards,
Ganesh R -
Post Author: eskimo42
CA Forum: Formula
I have an ecommerce DB which I am trying to report on using Crystal
Reports 2008. Please bear with me, this is my first time using Crystal
Reports. Here is my issue: The
order creation date field in the eCommerce DB is being pulled as a Unix
Timestamp. After some research online I have found that this formula
should help me convert the timestamps into a readable format:DateAdd (u201Dsu201D,{jos_vm_orders1.cdate}-18000, #1/1/1970#)So
I have created numerous formula fields, Formatting Formulas, Custom
Functions, and all I can seem to come up with is this error:The ) is missing. I
really hope someone can walk me through how exactly I can convert a DB
field which appears in a report to, a readable time stamp with that
formula I have above. Thanks,EvanPost Author: bettername
CA Forum: Formula
Glad that worked!
Since Crystal doesn't support UnixTimeStamp<->DateTime conversion (c'mon guys!), you're going to have to write a formula for each field that you want to display that uses a Timestamp field (boring, yes!), and drag each of the formulas onto the page. I sure hope I'm missing something there...
You could create a custom function to save some typing - have a look at http://publib.boulder.ibm.com/infocenter/radhelp/v6r0m1/index.jsp?topic=/com.businessobjects.integration.eclipse.doc.crdesigner/reportdesigner/crconcustomfunctions.htm, but essentially the code is:
Function (numbervar UnixTimeStamp)DateAdd ("s",UnixTimeStamp-18000, date(1970,01,01))
That way, each time you want to convert a field, you just type a formula that says "UnixToDateTime ({yourTable.YourField})"
I think you know where to create a formula (View - Field Explorer). Once you've created the formula, drop it in the details section, then goto 'Insert' - 'Group', choose the formula and the rest should be obvious... -
Difference between timestamp oracle datatype as unix timestamp
Hi
We are having a column in our table as create_ts which is the time, the row is updated. We are in need to get this time in Pro*c as unix timestamp type to find out the oldest row from a set of rows.
I found that the following query works when I convert to date and find out the difference.
select TO_NUMBER((TO_DATE (TO_CHAR (CREATE_TS, 'YYYY-MON-DD HH24:MI:SS'),'YYYY-MON-DD HH24:MI:SS') - to_date('01.01.1970 00:00:00','dd.mm.yyyy HH24:mi:ss')) * 24 * 60 * 60 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600 ,9999999999) as timestamp from customer;
However when I keep it as timestamp type I'm getting some error
select TO_NUMBER((CREATE_TS - to_timestamp('01.01.1970 00:00:00','dd.mm.yyyy HH24:mi:ss'))* 24 * 60 * 60 *1000 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600000 ,9999999999999) as timeints from customer;
ERROR
ORA-30081: invalid data type for datetime/interval arithmetic
30081. 00000 - "invalid data type for datetime/interval arithmetic"
FYI: since if I convert to date type, we're losing the microseconds, we had to find the difference using the timestamp type.
thanksWhen you take a difference between two timestamps, You dont get a number(like substracting dates). You get a string that has number of days,hours,minutes and seconds.
You can break the string though,
SQL> SELECT SUBSTR(today,1,30) today,
2 SUBSTR(tomorrow,1,30) tomorrow,
3 SUBSTR((tomorrow-today), INSTR((tomorrow-today),' ')+7,2) "SS",
4 SUBSTR((tomorrow-today), INSTR((tomorrow-today),' ')+4,2) "MI",
5 SUBSTR((tomorrow-today), INSTR((tomorrow-today),' ')+1,2) "HH",
6 TRUNC(TO_NUMBER(SUBSTR((tomorrow-today),1, INSTR(tomorrow-today,' ')))) "Days"
7 FROM (SELECT TO_TIMESTAMP(SYSDATE) today,TO_TIMESTAMP(SYSDATE+1) tomorrow FROM dual);
TODAY TOMORROW SS MI HH Days
10-MAR-11 12.00.00 AM 11-MAR-11 12.00.00 AM 00 00 00 1
SQL>
SQL> G. -
hi all,
i need to convert current time to unix timestamp. actaully i'm a PHP programmer but i plan to use jsp in the future. when i write web applications with PHP, i use mktime() function which converts any given time to unix timestamp value. so i store returned integer value to database as an integer field. this helps me when i need to compare dates with sql commands. and when i need to reconvert this integer to date value i use anoher php function date().
so my question is, how can i do such a thing with java? people talk about a class java.sql.Timestamp, is it the timestamp that i look for?
any helps (especially code samples) will be useful...ok i found out how to get the time in miliseconds. by getTime() method of Date class. but i still have problems. if u interested this topic is moved to java programming forum under title "date in miliseconds".
-
I tryed to sort my pictures with buying Apps and following suggestion from apple, but without any success. In my opinion, the real solution is for Apple to offer us a choice of the photo sort order in ITunes. My preference would be filename, perhaps with options to choose the Date Taken attribute, file timestamp or date modified filestamp.
Not a problem when using iPhoto on a Mac, which the transfer of photos is primarily based on - not manually managing photo storage as seems to be common with Windoze.
The same should be available with a supported photo management app on a PC.
http://support.apple.com/kb/HT4221 -
How to Create a Unix Agent and data stage adapter
Hi Gurus,
I am new to this tool. We have installed trail version of tidal scheduler tool. Kindly let me know how to create a unix agent and data stage adapter using some screen shots. Also please let me know is it possible to create agents on trail version
Thanks,
Saravanan Viswanathanedburns wrote:
Can someone please tell me how to create a Unix Group on Leopard and how to add myself to that group?
Ed
man dseditgroupshould help. Look particularly at the examples.
Maybe you are looking for
-
How do I add a PDF file for download to my iWeb page?
How do I add a PDF file for download to my iWeb page? I have created one using Apples Pages program. Thanks!
-
Well I can understand the purpose of inner classes in multithreaded applications or where you need a continous monitoring, but I have always been wondering why use an inner application in a normal application. Any ideas?
-
On my Blackberry Z10 I got the error "The file could not be found. Check the URL and try again. If the URL is correct, check that your media card is properly inserted in your device." This came up when I simply clicked on an email. I don't have
-
Error accessing User-Database from Jython CLI
Hi All, once again, we experience a problem, when running udb commands from the Jython CLI, namely one of 'udb.g.la' or 'udb.u.la' (Others may be affected as well). Our user is logged on and the application handle works well for any other CLI calls.
-
I have seen this problem mentioned before, but I have never paid attention to it. Can't seem to find it. I can start DNG converter 8.4, but there's no button to start the conversion: Anybody have the solution?