473,662 Members | 2,390 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 2667
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
3291
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 date("Y-m-d", mktime(0,0,0,1,1,1930)); -> "1969-12-31" (since the result of mktime is "-1") But date() gets it though, so if I do
13
9286
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 three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted to the MYSQL date field. The type of field is INT (11) so that I can instead of the standard...
7
3425
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 could use inside this console application to make sure the MS SQL database is operational before I perform the insert?
2
2571
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 test(name,surname,email) VALUES('Bob', 'Sly', 'bobsly@yahoo.com')"; but instead of inputing the values directly, I want to insert them as variables like so:
0
3453
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 ...... The Time column is populated using a php time() function.
2
1485
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? And how can I add a day to the unixtime of today for example. Thx guys.
3
3353
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 records to a data base,for which i am using Typed dataSet.(I used DataSet Designer to create one) Then created a table adapter in which i have written query for INSERT , & set Database Direct property to true.(I didnt use a seperate methods for...
6
1891
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
3075
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 section: Discography --------------------- DiscID
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8762
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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 we have to send another system

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.