niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle
converting timestamp in milliseconds to date or vice-versa in oracle
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
ameyas7@yahoo.com
*nix forums beginner


Joined: 04 Feb 2005
Posts: 3

PostPosted: Fri Feb 04, 2005 4:20 pm    Post subject: Re: converting timestamp in milliseconds to date or vice-versa in oracle Reply with quote

Hi Rauf,

i got it ... just in case if you are interested.

select TO_DATE('1970-01-01', 'YYYY-MM-DD')+
max(numtodsinterval(to_number(timestamp_col)/1000,'SECOND')) from
your_table;

where timestamp_col is the column name which stores the timestamp and
your_table is the required table.


Quote:
On a side note... why use currentTimeMillis at all and store in
varchar2 field?... why not use sysdate and store it properly in the
Date column?

the timestamp is used for auditing purpose.
it stores the timestamp precisely, which is required at some of the
places in the system and the system is already in place so it would not
be advisable to change the type now Wink


cheers
amey
Back to top
Rauf Sarwar
*nix forums Guru


Joined: 03 May 2005
Posts: 353

PostPosted: Fri Feb 04, 2005 1:49 pm    Post subject: Re: converting timestamp in milliseconds to date or vice-versa in oracle Reply with quote

ameyas7@yahoo.com wrote:
Quote:
hey folks,

we have a varchar2 col which stores the timestamps (records r added
frm
java app which logs the currentTimeInMillis on that System)
now i want to write a procedure which will delete records older than
say 45 days
i can get the current date using sysdate but this is in DATE format
whereas my column is in varchar2 (also the value is in millis)
how do i convert from millis to date or vice-versa


regards
amey

System.currentTimeMillis() as described in javadocs "the difference,
measured in milliseconds, between the current time and midnight,
January 1, 1970 UTC"... so good luck doing the calculation in PL/SQL.

On a side note... why use currentTimeMillis at all and store in
varchar2 field?... why not use sysdate and store it properly in the
Date column?

Regards
/Rauf
Back to top
Jim Kennedy
*nix forums Guru


Joined: 30 Apr 2005
Posts: 367

PostPosted: Fri Feb 04, 2005 1:46 pm    Post subject: Re: converting timestamp in milliseconds to date or vice-versa in oracle Reply with quote

<ameyas7@yahoo.com> wrote in message
news:1107525884.144586.315700@z14g2000cwz.googlegroups.com...
Quote:
hey folks,

we have a varchar2 col which stores the timestamps (records r added frm
java app which logs the currentTimeInMillis on that System)
now i want to write a procedure which will delete records older than
say 45 days
i can get the current date using sysdate but this is in DATE format
whereas my column is in varchar2 (also the value is in millis)
how do i convert from millis to date or vice-versa


regards
amey

So you store numbers in a varchar field. That makes sense. How would you

do it by hand? Date can be converted to a variety of formats, look at the
doco. (sql reference book).
Jim
Back to top
ameyas7@yahoo.com
*nix forums beginner


Joined: 04 Feb 2005
Posts: 3

PostPosted: Fri Feb 04, 2005 1:04 pm    Post subject: converting timestamp in milliseconds to date or vice-versa in oracle Reply with quote

hey folks,

we have a varchar2 col which stores the timestamps (records r added frm
java app which logs the currentTimeInMillis on that System)
now i want to write a procedure which will delete records older than
say 45 days
i can get the current date using sysdate but this is in DATE format
whereas my column is in varchar2 (also the value is in millis)
how do i convert from millis to date or vice-versa


regards
amey
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 2:19 am | All times are GMT
navigation Forum index » Databases » Oracle
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Move Oracle 10g database to another location Selt Server 0 Fri Jul 21, 2006 2:14 pm
No new posts Oracle runtime Spitfire Server 0 Fri Jul 21, 2006 1:18 pm
No new posts Oracle Text Score Computation jatinder.1975@gmail.com Server 0 Fri Jul 21, 2006 1:00 pm
No new posts Problem with Date::Manip Ted Byers Perl 1 Fri Jul 21, 2006 4:23 am
No new posts Can a trigger insert records into another oracle server Tauqir Server 2 Fri Jul 21, 2006 12:27 am

Personal Loans | Watch Anime Online | Sudoku Software | Loans | Advance Auto Parts
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1852s ][ Queries: 20 (0.0825s) ][ GZIP on - Debug on ]