473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

time conversion

1075329297.572
This is unix time where 1075329297 is seconds 572 is milliseconds.
first il store this time in oracle database.when i am retrieving it i want this date into yyyy-dd-mm format. Is it possible to do it in oracle.(using convert function)
or is there some other way?
reply
Mar 5 '08 #1
1 3200
amitpatel66
2,367 Expert 2GB
1075329297.572
This is unix time where 1075329297 is seconds 572 is milliseconds.
first il store this time in oracle database.when i am retrieving it i want this date into yyyy-dd-mm format. Is it possible to do it in oracle.(using convert function)
or is there some other way?
reply
Try this code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE OR REPLACE
  3.     FUNCTION unixts_to_date(unixts IN PLS_INTEGER) RETURN DATE IS
  4.         /**
  5.          * Converts a UNIX timestamp into an Oracle DATE 
  6.          */
  7.         unix_epoch DATE := TO_DATE('19700101000000','YYYYMMDDHH24MISS');
  8.         max_ts PLS_INTEGER := 2145916799; -- 2938-12-31 23:59:59
  9.         min_ts PLS_INTEGER := -2114380800; -- 1903-01-01 00:00:00
  10.         oracle_date DATE;
  11.  
  12.         BEGIN
  13.  
  14.             IF unixts> max_ts THEN
  15.                 RAISE_APPLICATION_ERROR(
  16.                     -20901,
  17.                     'UNIX timestamp too large for 32 bit limit'
  18.                 );
  19.             ELSIF unixts <min_ts THEN
  20.                 RAISE_APPLICATION_ERROR(
  21.                     -20901,
  22.                     'UNIX timestamp too small for 32 bit limit' );
  23.             ELSE
  24.                 oracle_date := unix_epoch + NUMTODSINTERVAL(unixts, 'SECOND');
  25.             END IF;
  26.  
  27.             RETURN (oracle_date);
  28.  
  29. END;
  30.  
  31. SQL> SELECT unixts_to_date(1075329297) from dual
  32.  
  33.  
Mar 5 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: flupke | last post by:
Is there an easy to convert following hour notation hh:mm to decimals? For instance 2 hours and 30 minutes as 2:30 to 2,50 I don't really know where to search for this kind of conversion. ...
3
by: garreth.kelly | last post by:
is it possible in sql to convert a 6 digit integer in to a time field with out converting to character and then substringing e.g 161201 to 16:12:01
1
by: heirou | last post by:
I'm a novice in this subject....I've made a database that requires a time conversion. For example, if local time is 1200, determine the time in Korea. I use two fields: a date field, and a time...
3
by: Chandu | last post by:
Hi, I am working on awk programming which is similar to C programming and have got a doubt about time function returning a float value. Ex: 01:01:30 should return 61.5 when i have tried my way i...
5
by: Paulers | last post by:
Hello, I'm working on an app that requires the functionality to convert the time in Austrailia to the time in New York (EST). I am wondering, what is the bestway to approach this in vb.net? Is...
3
by: moni | last post by:
Hi, I wanted to convert a time value in the form of time_t into a readable form in C# or vice versa, in order to be able to subtract two time values and give the result in msecs. eg. I...
3
by: moni | last post by:
This is all in C: I have 2 time values: System time and an input from the user. 1) System time is in the form of seconds from 1/1/1970 calculated by using time_t secs;
3
by: Evan Klitzke | last post by:
Although it is not present in ANSI C, the GNU version of stftime supports the conversion character %z, which is a time offset from GMT. The four digit time offset is required in RFC 2822...
2
by: Renee Zarazinski | last post by:
I have two fields Time-in & Time-out that are in military time. I have to calculate the difference (to get the total amt. of time spent working) then show the time as clock time. I've only been...
2
by: andreas.profous | last post by:
Hi all, I have the following problem: There are strings describing a UTC time, e.g. " 2008-01-15 22:32:30" and a string reflecting the time zone e.g. "-05:00". What is an elegant way of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.