Solved

Converting minutes to hh mm

Posted on 2008-10-25
7
400 Views
Last Modified: 2012-05-05
Hi

Currently I am using  CAST(flexcel.unformatted_remaining / 60 AS varchar(7)) + ':' + RIGHT('00' + CAST(flexcel.unformatted_remaining % 60 AS varchar(3)), 2) to convert minutes to HH:MM. this works well when the Number of minutes is positive i.e 01:10  , however if the number is negative i.e -10:05 problems arise with the display I have tried changing  varchar(3)), 2 to varchar(3)), 3 and different combinations
but when I get the negative right the posetive show wrong and visa  versa
0
Comment
Question by:Camnoc
[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
  • 3
7 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22805249
well, when you get the number of minutes (i assume you use datediff) apply the abs function to it, this way it will always be positive
0
 

Author Comment

by:Camnoc
ID: 22805501
What is the abs function. I am using datediff to calculate the .time to minutes. Please understand I am new to sql.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22805995
This is what momi is referring too:
http://msdn.microsoft.com/en-us/library/ms189800.aspx

SELECT ABS(-200) ;
==> 200
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:Camnoc
ID: 22806743
This seems to give a result in decimal. I am trying to display -15 min as -00:15 or 15 as 00:15 ??
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22807461
Was just giving you an example of what was being suggested, you will have to same formula you had above with absolute inserted.

CAST(ABS(flexcel.unformatted_remaining) / 60 AS varchar(7)) + ':' + RIGHT('00' + CAST(ABS(flexcel.unformatted_remaining) % 60 AS varchar(3)), 2)
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22807472
If we are misunderstanding and you are trying to show negatives, then you can do this instead.

CAST(flexcel.unformatted_remaining / 60 AS varchar(7)) + ':' + RIGHT('00' + CAST(ABS(flexcel.unformatted_remaining) % 60 AS varchar(2)), 2)

Open in new window

0
 

Author Closing Comment

by:Camnoc
ID: 31510011
THANK YOU
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

756 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