Timestamp in ISO 8601 compliant standard [message #448755] |
Thu, 25 March 2010 02:11  |
mjkreddy1927
Messages: 20 Registered: February 2007
|
Junior Member |
|
|
Hi Friends,
I Need help from you all,
My senario is like
i need to insert and retrive the date feilds in
ISO 8601 compliant standard ie..YYYY-MM-DDThh:mm:ss±hh:mm.
i have many locations to get reflected.
Please help me out with any suggestions or Docs or links. Relevent
Regards
JK
|
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #448762 is a reply to message #448757] |
Thu, 25 March 2010 02:27   |
mjkreddy1927
Messages: 20 Registered: February 2007
|
Junior Member |
|
|
Michel Cadot wrote on Thu, 25 March 2010 02:15SQL> select to_char(systimestamp,'YYYY-MM-DD"T"hh24:mi:sstzh:tzm') isodt from dual;
ISODT
-------------------------
2010-03-25T08:03:40+01:00
Regards
Michel
Hi Michel,
Thanks for the imm reply
This is fine while selecting but i want to insert and select and selecting the existing date feilds&rows aswell.
[Updated on: Thu, 25 March 2010 04:28] by Moderator Report message to a moderator
|
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #448769 is a reply to message #448762] |
Thu, 25 March 2010 02:35   |
 |
Michel Cadot
Messages: 68733 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
To insert you use TO_TIMESTAMP with the same format.
You cannot use a DATE datatype but have to use one of the TIMSTAMP% ones as DATE does not know nor support time zone.
You can nevertheless use DATE if you assume/convert all your date/time into DB time zone and use DBTIMEZONE function to retrieve the date:
SQL> select to_char(sysdate,'YYYY-MM-DD"T"hh24:mi:ss')||dbtimezone osidt from dual;
OSIDT
-------------------------
2010-03-25T08:03:30+01:00
Regards
Michel
Tell me and I'll forget; show me and I may remember; involve me and I'll understand
[Updated on: Thu, 25 March 2010 04:29] Report message to a moderator
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #448785 is a reply to message #448769] |
Thu, 25 March 2010 03:50   |
mjkreddy1927
Messages: 20 Registered: February 2007
|
Junior Member |
|
|
Michel Cadot wrote on Thu, 25 March 2010 02:35To insert you use TO_TIMESTAMP with the same format.
You cannot use a DATE datatype but have to use one of the TIMSTAMP% ones as DATE does not know nor support time zone.
You can nevertheless use DATE if you assume/convert all your date/time into DB time zone and use DBTIMEZONE function to retrieve the date:
SQL> select to_char(sysdate,'YYYY-MM-DD"T"hh24:mi:ss')||dbtimezone osidt from dual;
OSIDT
-------------------------
2010-03-25T08:03:30+01:00
Regards
Michel
Tell me and I'll forget; show me and I may remember; involve me and I'll understand
Hi Still i am unable to follow the INSERT way.. can you please give me the syantax or example.
Do we need to set or alter session before doing that?
Thanks Michal
[Updated on: Thu, 25 March 2010 04:28] by Moderator Report message to a moderator
|
|
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #448797 is a reply to message #448785] |
Thu, 25 March 2010 04:24   |
 |
Michel Cadot
Messages: 68733 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote:Hi Still i am unable to follow the INSERT way.. can you please give me the syantax or example.
What about showing us what you tried?
What is the case you want to achieve? TIMESTAMP or DATE?
Here's an example for timestamp, I let you do it for date accordingly to your case and need.
insert into mytable (mytimestamp)
values (to_timestamp('2010-03-25T08:03:30+01:00','YYYY-MM-DD"T"hh24:mi:sstzh:tzm'));
Or something like that, I didn't check it.
Regards
Michel
Tell me and I'll forget; show me and I may remember; involve me and I'll understand
[Updated on: Thu, 25 March 2010 04:28] Report message to a moderator
|
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #448804 is a reply to message #448800] |
Thu, 25 March 2010 04:42   |
mjkreddy1927
Messages: 20 Registered: February 2007
|
Junior Member |
|
|
Michel Cadot wrote on Thu, 25 March 2010 04:33Or rather:
insert into t values
(from_tz(to_timestamp('2010-03-25T08:03:30','YYYY-MM-DD"T"hh24:mi:ss'),'+01:00'));
Now it depends on what is the exact stuff you get and in which exact table you want to store.
Regards
Michel
Tell me and I'll forget; show me and I may remember; involve me and I'll understand
Hi,
For inserting the Such date type what should be the datatype we need to use? TIMESTAMP WITH TIME ZONE?????
i did:
Alter session set NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD"T"HH24:MI:SSTZR';
SQL> create table table_tstz(c_id NUMBER,c_tstz TIMESTAMP WITH TIME ZONE);
|
|
|
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #448821 is a reply to message #448819] |
Thu, 25 March 2010 05:27   |
mjkreddy1927
Messages: 20 Registered: February 2007
|
Junior Member |
|
|
Michel Cadot wrote on Thu, 25 March 2010 05:25To store a timezone, no.
To do what you want, it depends on your environment, I told you about alternative ways in a previous post.
Note: a lone interrogation mark is sufficient to indicate this is a question, you don't need to multiply them (unless you want to make a breeding).
Regards
Michel
thanks michel, for the responce
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #449030 is a reply to message #448821] |
Fri, 26 March 2010 05:43   |
mjkreddy1927
Messages: 20 Registered: February 2007
|
Junior Member |
|
|
mjkreddy1982 wrote on Thu, 25 March 2010 05:27Michel Cadot wrote on Thu, 25 March 2010 05:25To store a timezone, no.
To do what you want, it depends on your environment, I told you about alternative ways in a previous post.
Note: a lone interrogation mark is sufficient to indicate this is a question, you don't need to multiply them (unless you want to make a breeding).
Regards
Michel
thanks michel, for the responce
Hi
Here i have done something please check and give me some comments..wethere is this helpfull for converting the existing timestamp to required timezone.
Convert_TimeZone(Date, From Timezone, To TimeZone)
Function:
create or replace
function CONVERT_TimeZone (dt in timestamp, DestinationTimeZone in varchar2, SourceTimeZone in varchar2)
return timestamp with time zone
as
retval timestamp with time zone
begin
retval := from_tz(dt, timezone1) at time zone SourceTimeZone;
return retval;
end;
Function will return null if there's exception.
select CONVERT_TimeZone(to_timestamp('03/18/2010 15:24','mm/dd/yyyy hh24:mi'),'-5:00','+9:30') from dual ;
Output: 3/19/2010 5:54:00 AM
UNIX Script
Regards
Jk
CM: Added [code] tags, please do so yourself next time, see the orafaq forum guide if you're not sure how.
[Updated on: Tue, 15 June 2010 11:41] by Moderator Report message to a moderator
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #449032 is a reply to message #449030] |
Fri, 26 March 2010 05:47   |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
mjkreddy1982 wrote on Fri, 26 March 2010 10:43Function:
create or replace
function CONVERT_TimeZone (dt in timestamp, DestinationTimeZone in varchar2, SourceTimeZone in varchar2)
return timestamp with time zone
as
retval timestamp with time zone
begin
retval := from_tz(dt, timezone1) at time zone SourceTimeZone;
return retval;
end;
Function will return null if there's exception.
Not as you've got it written there it won't, you'd need to add an exception handler.
|
|
|
Re: Timestamp in ISO 8601 compliant standard [message #449040 is a reply to message #449032] |
Fri, 26 March 2010 06:29   |
mjkreddy1927
Messages: 20 Registered: February 2007
|
Junior Member |
|
|
cookiemonster wrote on Fri, 26 March 2010 05:47mjkreddy1982 wrote on Fri, 26 March 2010 10:43Function:
create or replace
function CONVERT_TimeZone (dt in timestamp, DestinationTimeZone in varchar2, SourceTimeZone in varchar2)
return timestamp with time zone
as
retval timestamp with time zone
begin
retval := from_tz(dt, timezone1) at time zone SourceTimeZone;
return retval;
end;
Function will return null if there's exception.
Not as you've got it written there it won't, you'd need to add an exception handler.
What type of exception i need to handel? is that mandate? please link me out..
|
|
|
|