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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math Calculation Help... Working with stripping Minutes 3

Status
Not open for further replies.

txgeekgirl1

Programmer
Sep 10, 2009
85
US
I have the NewDuratn rounding and calculating correctly. Here is the issue. My first 2 values are 1.00 and 2.00 - I need to further that and calculate minutes back into minutes.... example - I have a 1.94 which is like 110 min. I have to divide .94/60 and add it back on. In VFP 6 I don't have a lot of the newer options. I have tried string conversion then manipulating but with my first two values it's rounding something awful.

Code:
SELECT CONNECTOR, ;
	CliID, ;
	Duratn, ;
	ROUND(Duratn/60,2) AS NewDuratn ;
	FROM MyTimes_ ;	
	ORDER BY Connector ;
	INTO CURSOR Dura2_

This calculation is the middle piece I need. for the last piece below.

Code:
IIF(sv.SvcCode = "3104",VAL(RIGHT(Duratn,2)),IIF(VAL(RIGHT(Duratn, 2)) < 8.00, 0.00, IIF(VAL(RIGHT(Duratn, 2)) < 23.00, 0.25, ;
				IIF(VAL(RIGHT(Duratn, 2)) < 38.00, 0.50, IIF(VAL(RIGHT(Duratn, 2)) < 53.00, 0.75, 1.00))))) as dMin, ;
 
The % operator actually is the same as MOD()
Mod(duratn,60) is the same as Duratn % 60.

Bye, Olaf.
 
Yes but MOD gives you min as min not as a fraction of the hour.

 
Yes, both MOD and % give minutes in the range of 0-59, like needed in a time string in the form of hh:mm or hh.mm

Go back to VB.

Bye, Olaf.
 
I know - I know - I cannot wait until we are FULLY converted - counting the days.
 
If you find all this so archaic, you can actually add seconds to a datetime to get a new datetime. If you add seconds to a datetime being at midnight, the time portion is the duration in hours and minutes.

for example:

? DTOT(Date())+Duratn*60

The time portion, especially the hh:mm part of that is what you want.

And if you remove *60 you actually can use the mm:ss part of the datetime string as your result.

And TToC(Datetime(),2) gives you just the time portion.

Bye, Olaf.
 
See Olaf - you VFP programmers live for this. You should have heard the Woot Woot when I got my array to fill in VFP. The stuff I can knock out in plain SQL or VB.Net takes me sometimes hours in VFP - If my boss didn't move to CIO from a Programmer background with Basic, C, and VFP, I would be screwed.
 
I don't argue that everything is much easier, if you know a language.

But no matter what language you use you need to know your problem and be able to describe it before you solve it.

You can always find things easy in one lanaguage and hard in another and vice versa.

But you could have had an answer much earlier if you would have been capable to describe what you need just in natural language. minutes rounded to the next quarter and minutes converted to a time string in the format hh.mm

Is that so hard do describe? From your attitude I can only assume you already came here with a bad temper and prejudices about the complexity of the foxpro language and not wanting to learn anything foxpro, as you move away from it anyway.

Bye, Olaf.
 
I have no problems with learning new things Olaf, and I tried to be thorough in my initial description - and all henceforth.

My problem is that I am not a geek. I was a self taught coder to make money to get through college in Politcal Science to go to Law School. I designed web sites and databases. When I became a single mom I decided coding paid more that being a lawyer and then got a job where they are slow to move into the 21st century but pay very well.
 
[&nbsp;]

If a survey was done, I think we would find that a very large percentage of FoxPro programmers, myself included, are self-taught and have had to learn many things the hard way. We all need help. That is the purpose of this forum, to help us learn so we can get the problems solved and move on to the next problem. Programming is really nothing more than constantly solving problems, often problems that will drive us nuts if we let them get to us.

Programmers are paid well because they can convert the needs of the user into baby steps that the computer can understand. Not many people are capable of doing that, hence the pay scales of programmers.

MOD and % were noted in many posts after my first post as being part of the solution to the problem. Did you not see them? If you did, and they were new to you, why did you not research what they did? If you had, you would have probably been able to solve your problem long before my second post.

At any rate, I am assuming that your problem has now been solved. On to the next problem!!!!

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
[&nbsp;]
Code:
STR(INT(x/60)) + "." + RIGHT("00" + STR(MOD(x,60)),2)

After looking at this for a while, I realized that this still will not solve your problem. So, if you used that without further modifications, you will have more problems.

For example, if you substitute [tt]x[/tt] with 121, your result will be "[tt] 2. 1[/tt]", not exactly what you want. I assume that the answer you really want is "[tt]2.01[/tt]".

The 6th post by KarenJB suggested the following similar solution:

Code:
LTRIM(STR(INT(nMin/60))) + ':' + LTRIM(STR([b][red]MOD[/red][/b](nMin,60)))

Instead of the desired "[tt]2:01[/tt]" this produces "[tt]2:1[/tt]", also incorrect, when you substitute nMim with 121. So, lets do the following:

Code:
LTRIM(STR(INT(x/60))) + "." + RIGHT("00" + LTRIM(STR(MOD(x,60))), 2)

When 121 is plugged into this, the result is "[tt]2.01[/tt]", which I believe is exactly what you want.

Furthermore, all of the following also produce exactly the same correct results.

Code:
LTRIM(STR(INT(x/60))) + "." + RIGHT("00" + LTRIM(STR(x % 60)), 2)

LTRIM(STR(INT(x/60))) + "." + PADL(LTRIM(STR(MOD(x,60))), 2, "0")

LTRIM(STR(INT(x/60))) + "." + PADL(LTRIM(STR(x % 60)), 2, "0")

There are undoubtedly other ways in FoxPro to solve the same problem.

And the usual disclaimer: Not tested.


mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
It doesn't really matter much if you self taught programming or not, there is no science solving any problems, but it's a talent to fomulate problems in a way others might help.

In your first post you showed some sample code and at least three people including me say your problem was not understandable.

But I think you initially could have said us, that you initially have minutes and need them transformed to quarters of hours expressed as fractions of hours as in 0.25,0.5,0.75,1.0 and so on plus you also need the minutes transformed in hh.mm

This is the problem and stated in this way it's easy to solve in any language I'm pretty sure.

People having the talent in stating the problem often can solv it themselves. Those people more often come here to answer than to ask.

From that perspective it's no wonder you asked here. I think if you could have stated your problem like I did now, you could have solved it yourself. I think your real problem was you didn't know what your task was. If that's not the case I'm just puzzled what was so hard to explain it.

Finally I want to add, I'm not angry at you at all, I'm just puzzled.

Bye, Olaf.
 
You are all wrong guys (including me)! Or am I a ghost and nobody see my posts? For example I had this:

Code:
int( Duration ) && hours 
int( Duration * 60 ) % 60 && minutes

Huh where is that damn MOD in this code. If I were yet another Obiwan I might have known that I should use MOD() instead of %. The poster, who had respect to repliers tested the replies. If MOD() had been known by one the repliers then the solution would be found before the return of jedi. One learns a new thing every day:)




Cetin Basoz
MS Foxpro MVP, MCP
 
I just threw out my answer using the integer and mod functions as a quick example. I was a little hazy on what the final desired outcome was so I figured that would suffice. Int gave hours and mod gave the minutes. You can then turn the minutes into 1/4 incremental units with a case statement or display it as hours:min or whatever your heart desires. I guess if I'd been a bit more clear we might have moved on sooner and ended this MODness.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top