Click here to Skip to main content
16,005,281 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a database field END_TIME of type varchar.
The data in it of following pattern:

END_TIME
---------
09/06/2013 05:07:02 PM


Now I only need "05:07:02 PM" part. How can I achieve it?


Also I have
TOTAL_TIME
--------------
00 hrs 01 mins 40 secs


I need to show only minutes. Like 1.4 mins or 1 min 40sec.

Please help
Posted

Hi ,

You can use Substring for extraction of part of string like this, if your column name is salesdate and it contains date given by you , data type of this column is varchar. then you can go for this.


select SUBSTRING(salesdate,11,14 ) from test

In substring function salesdate is columnname,11 is starting point of extraction,14 is length upto which you need to extract the string.

This way you can do extraction and then concatination to join two values.hope this will helps.


Regards,
Mubin
 
Share this answer
 
Hi,

You can try below code also...
SQL
DECLARE @END_TIME VARCHAR(50)
SET @END_TIME = '09/06/2013 05:07:02 PM'
SELECT SUBSTRING(@END_TIME, CHARINDEX(' ',@END_TIME ,1)+1,20)

Let me know what logic you want to use to frame "00 hrs 01 mins 40 secs" to "1.4 mins or 1 min 40sec"

Regards,
GVPrabu
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900