Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AM/PM Datetime to Military Datetime 1

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
0
0
US
When I select the field "DTTM_STAMP" and look at "View SQL", it has "TO_CHAR(CAST((DTTM_STAMP) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF')" (result example: 04/10/2019 3:16:59PM).

I thought this expression "TO_CHAR(CAST(DTTM_STAMP) AS TIMESTAMP),'YYYY-MM-DD HH24:MI:SS') would work but it doesn't like the ":" in the time to get "2019-04-10 15:16:59" When I change the colons to periods then it works "2019-04-10 15.16.59"

I would appreciate any help!

 
What is the exact data type for dttm_stamp?
I have tried testing your query on both a timestamp(3) and date data type, and it works fine in both cases.
If you are pressed for time, you could always go for the kluge:
Code:
REPLACE(TO_CHAR(CAST(DTTM_STAMP) AS TIMESTAMP),'YYYY-MM-DD HH24.MI.SS'),'.',':')
but this is ugly.
 
Hi carp,

I like kluge but it didn't work (results are blank and when I remove it then there are results). The field is a DateTm type. I was hoping that I could have it in my oracle query but I think I can use the program that I will be importing the data to summarize it, etc. to change the "." to ":"

Thank you looking into my problem! I appreciate it!
 
Sorry to hear that, kernal. There is something odd going on, though. Your original approach worked fine on our setup, and the kluge should also have worked. But if you've got a workaround, I guess it's time to head into the weekend!
Best of luck, and post back if you still have an issue. I'm sure we can get this worked out.
 
Yor results do not match your select. You said

"I select the field "DTTM_STAMP" and look at "View SQL", it has "TO_CHAR(CAST((DTTM_STAMP) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF')" (result example: 04/10/2019 3:16:59PM)."

a format mask of 'YYYY-MM-DD-HH24.MI.SS.FF' can't produce a result of '04/10/2019 3:16:59PM'. It would produce a result of '2019-04-10-15.16.59.00', every time. If you use

to_char(DTTM_STAMP,'MM/DD/YYYY HH:MI:SSPM') will produce a result of '04/10/2019 3:16:59PM'

Bill
Lead Application Developer
New York State, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top