Solved

How to truncate seconds in datetime or timestamp in Oracle

Posted on 2012-04-05
9
3,474 Views
Last Modified: 2012-04-29
The following query below only displays date of datetime field

Select Trunc(To_timestamp(adstime, 'yyyy-mm-dd hh24:mi:ss'), 'MI') time from hp_datetime;;

I only want to show 08:25 instead of 08:25:10

Thanks
0
Comment
Question by:Talitha30
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
9 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 360 total points
ID: 37812531
Is adstime a varchar2?

To remove the seconds, use to_char to turn it back into a string.  Just use the same format mask without the seconds.
0
 

Author Comment

by:Talitha30
ID: 37812538
yes it's a varchar datatype
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 360 total points
ID: 37812566
Ok then, just wrap a to_char around it

Select to_char(Trunc(To_timestamp(adstime, 'yyyy-mm-dd hh24:mi:ss'), 'MI') ,  'yyyy-mm-dd hh24:mi') time from hp_datetime;
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37812576
Come to think of it, wouldn't a regex_replace be better to manipulate the varchar2 to truncate the minutes and remove the seconds?
0
 

Author Comment

by:Talitha30
ID: 37812636
That's true.....
Your solution worked perfectly!
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 140 total points
ID: 37812950
don't even need a regexp

substr(adstime,12,5)   -- to get just the hours:minutes

substr(adstime,1,16)   -- to get the date with hours:minutes
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 37883470
why the B?  especially if the answer worked "perfectly"  ?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question