×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

AM/PM Datetime to Military Datetime

AM/PM Datetime to Military Datetime

AM/PM Datetime to Military Datetime

(OP)
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!

RE: AM/PM Datetime to Military Datetime

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.

RE: AM/PM Datetime to Military Datetime

(OP)
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!

RE: AM/PM Datetime to Military Datetime

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.

RE: AM/PM Datetime to Military Datetime

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close