473,513 Members | 4,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inserting unixtime in database

26 New Member
hi
i have unixtime format 1075329297.572 how do i store it in database.that is with what datatype.i tried to store unixtime using date, timestamp but it does not work.
but with varchar2 it works. but ifi store with varchar2 i cant perform conversion functions.
i want to convert unix time into yyyy-dd-mm hh-mm-ss format.
help me out
thanks in advance
Mar 28 '08 #1
1 2646
amitpatel66
2,367 Recognized Expert Top Contributor
Try this function that converts Unix_Time to Date:

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

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

Similar topics

12
3276
by: Sandman | last post by:
Hi. On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with PHP. That is, when feeding a function that turns dfates into unixtime, such as mktime() and strtotime() print...
13
9267
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
7
3415
by: Jared Evans | last post by:
I developed a console application that will continually check a message queue to watch for any incoming data that needs to be inserted into MS SQL database. What would be a low-cost method I...
2
2551
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
0
3444
by: Dan | last post by:
I'am having problem with the SQL statement... MySql Database Table structure for phpnews_news is id int unsigned auto_increment primary key, posterid int, postername char(40), time int, etc...
2
1478
by: KfirShtober | last post by:
Hello. I have a task to develop a calendar in C#, therefore - I need to use unixtime I think. But I don't know how to, can some one explain to me how to convert the date of today to unix time?...
3
3342
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
6
1883
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
2
3058
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.