473,669 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

to_timestamp fomatting of Dates

rsrinivasan
221 New Member
I run this code

select to_timestamp('3 1-12-2006 23:34:59','DD-MM-YYYY HH24:MI:SS') from dual;

But it Displays like this

31-DEC-06 11.34.59.000000 000 PM

But i expect this format
"MM/DD/YYYY HH:MI AM"

The separator should be /(slash) instead of -(hyphen).
The Second shoould not be displayed.

plz help me...
May 8 '07 #1
12 36916
frozenmist
179 Recognized Expert New Member
Hi,
Try this
Expand|Select|Wrap|Line Numbers
  1.  
  2. select to_char(to_timestamp('31-12-2006 23:34:59','DD-MM-YYYY   H24:MI:SS'),'MM/DD/YYYY HH12:MI AM') from dual
  3.  
This should solve it.
Cheers
May 8 '07 #2
rsrinivasan
221 New Member
Hi,
Try this
Expand|Select|Wrap|Line Numbers
  1.  
  2. select to_char(to_timestamp('31-12-2006 23:34:59','DD-MM-YYYY   H24:MI:SS'),'MM/DD/YYYY HH12:MI AM') from dual
  3.  
This should solve it.
Cheers
Fine... This is worked as i expected, but the field should not be converted to string. Because further i have to sort that field. If it is converted to string i can't sort that field. Because it consists AM and PM field.

plz reply what i need..
May 8 '07 #3
debasisdas
8,127 Recognized Expert Expert
replace this by previous query

Expand|Select|Wrap|Line Numbers
  1. select to_char(to_timestamp('31-12-2006 23:34:59','DD-MM-YYYY   HH24:MI:SS'),'MM/DD/YYYY HH12:MI AM') from dual
  2.  

only add HH24 in place of H24
May 8 '07 #4
rsrinivasan
221 New Member
Ok Fine... This is worked as i expected, but the field should not be converted to string. Because further i have to sort that field. If it is converted to string i can't sort that field. Because it consists AM and PM field.

plz reply what i need..
May 8 '07 #5
frozenmist
179 Recognized Expert New Member
Hi,
You can store the value of date in the default Oracle format itself. So it would be possible for sorting. You can use the to_char function to change the format of the date to what you want when ever you are displaying.
Would this solve your problem?

Cheers
May 8 '07 #6
rsrinivasan
221 New Member
Thanks for ur reply...
My table oracle table format is

order_entry_dat e ---- date
order_entry_tim e ---- varchar2(10)

My client expects to concat these two fields and then sort that concatinated field. If i concat these two fields it is changed as string. then When i sort that field, it does not bother about AM and PM. It only sorts Date and Time.. it did not bother AM and PM..

thanks...
May 8 '07 #7
frozenmist
179 Recognized Expert New Member
Hi,
I think if you have the concatenated field as YYYY/MM/DD HH12:MI AM/PM
It would sort correctly.
Cheers
May 8 '07 #8
rsrinivasan
221 New Member
Hi,
No. If the concatenated field is String, it is not sorted correctly. Only sorted, when it is timestamp field.

If it is String, it looks like this after sorting,

01-JAN-07 01.00 AM
01-JAN-07 02.00 PM
01-JAN-07 03.00 AM
01-JAN-07 04.00 AM


But It should be

01-JAN-07 01.00 AM
01-JAN-07 03.00 AM
01-JAN-07 04.00 AM
01-JAN-07 02.00 PM

See Am and Pm closely....
May 8 '07 #9
frozenmist
179 Recognized Expert New Member
Hi,
If you store the concatenated field as YYYY/MM/DD HH12:MI AM/PM
Then you can sort using
(assume concatenated field is dt)
Select dt from table order by substr(dt,1,10) ,substr(dt,leng th(dt)-2,length(dt)),s ubstr(dt,11,5)

The first substring is for date, second for am/pm and third for time.
Would this help?
Cheers
May 9 '07 #10

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

Similar topics

8
5327
by: Riley | last post by:
The date fields being saved by a VB program were being saved as #2003-11-22#. For reasons unknown to me these dates began to be saved as "11/22/2003" All of these dates were made dates with the "DateValue" instruction and when used as input to Excel both formats sort as dates but not intermingled. All "11/22/2003" formated dates sort in date order but before the #2003/11/22#. What would cause the format of these dates to change and what...
7
1752
by: Alistair | last post by:
diary_date = request.form("diary_date") - (from a populated drop down list) strSQL = "SELECT saz_title, saz_text from saz_details where saz_date =#" & diary_date & "#" a response.write gives SELECT saz_title, saz_text from saz_details where saz_date =#07/06/2004#
5
2138
by: PW | last post by:
<rant> Sorry guys, but I just have to whinge. Dates in ASP are a total pain in the butt! I seem to get caught out so many times. I realise its my own fault, but going from the posts in this newsgroup and others, I'm not the only one. Its just a poorly addressed issue within ASP. So for all your poor buggers out there that are having problems, particularly with european date formats, here is my solution. I have the user enter their...
10
3283
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: http://www.ipwebdesign.net/kaelisSpace/useful_tableSort.html This works great except it doesn't sort my UK formatted dates properly, and I end up with something like this: Birth Date (dd/mm/yyyy)
7
12808
by: Bambero | last post by:
Hello all Problem like in subject. There is no problem when I want to count days between two dates. Problem is when I want to count years becouse of leap years. For ex. between 2002-11-19 2003-11-19
1
3742
by: kaab kaoutar | last post by:
Hi, A client is using postgresql 7.1.3, and to_date() and to_timestamp() functions fail sometimes,However they never do in postgresql 7.3.2. Are these bugs? Thx _________________________________________________________________ Add photos to your messages with MSN 8. Get 2 months FREE*.
12
2434
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is dd/mm/yyyy, I have found that the dates I put in my holidays table are reversed into American dates. So, the wrong holiday dates are subtracted from the total workdays between the start and end dates. Is there an easy fix for this? ******Code...
1
15661
by: pitfour.ferguson | last post by:
My dbase has the start date and end date of each visit. How can I ask Access to list the day of the week of the start (easy), end (easy) and, more importantly, the dates of the visit itself - ie list the dates between the start and end date. Basically I am doing a day of the week analysis and need to know which day of the week is busiest.
2
2193
by: Jim Carlock | last post by:
(1) Does PHP provide any way to handle dates prior to 1980? I know there's problems with Microsoft Windows NT and all Windows NT operating systems will allow a date prior to 1980 to be placed upon a file, but it ends up not being able to display the date (probably an Windows Explorer specific issue). (2) I'm looking for for ways to store dates and process dates (dates only). This probably ends up as a database specific issue, so I'm...
0
8462
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
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8802
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
8658
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
7405
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...
0
5682
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
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
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
2
2028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.