Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Aug 16, 2017 10:51 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: time calculation
PostPosted: Thu Jul 30, 2009 10:27 am 
Offline

Joined: Tue Aug 29, 2006 4:04 am
Posts: 513
Location: Indonesia
Hi,
I'm trying to calculate the time duration to find the minute differences,
I've found some code on VB..
Private Function TimeDiff(Time1 As String, Time2 As String) As String
Dim MinsDiff As String
Dim TheHours As String
MinsDiff = DateDiff("n", Time1, Time2)
'If midnight is between times
MinsDiff = IIf(MinsDiff < 0, MinsDiff + 1440, MinsDiff)
TheHours = Format(Int(MinsDiff / 60), "00")
MinsDiff = Format(MinsDiff Mod 60, "00")
TimeDiff = TheHours & ":" & MinsDiff
End Function


Private Sub Command1_Click()
Dim x As String
x = TimeDiff(Text1.Text, Text2.Text)
MsgBox x
End Sub


I just wanna know if its possible to convert it to rb..


Thanks

Regards,
Rivo


Top
 Profile  
Reply with quote  
 Post subject: Re: time calculation
PostPosted: Thu Jul 30, 2009 10:46 am 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
Sure. Look up the totalseconds property for the Date class.

Since you know how many seconds are in a minute the resulting calculation is easy.

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
 Post subject: Re: time calculation
PostPosted: Fri Jul 31, 2009 7:00 am 
Offline

Joined: Tue Aug 29, 2006 4:04 am
Posts: 513
Location: Indonesia
I did, but I have a problem if I have to do calculation which is separated by ":" sign

Actually, I did it in VB, just dunno how to make it in RB,
this is exactly what I Need

Dim Str1$, Str2$, Str3$, Str4$
Text2.Text = DateTime.DateDiff("n", Text1.Text, Label1.Text)

Str1 = Text2.Text \ 60
Str2 = Text2.Text Mod 60
If Str1 > 24 Then
Text3.Text = "More than a day.."
Else
Text3.Text = Str1 & " hours & " & Str2 & " minutes"
Text3.Text = Format(Text3.Text, "hh:mm")
If Val(Text2.Text) > 480 Then
Label2.Caption = Text2.Text - 480
Str3 = Label2.Caption \ 60
Str4 = Label2.Caption Mod 60
Text4.Text = Str3 & " hours & " & Str4 & " minutes"
End If
End If


regards,
Rivo


Top
 Profile  
Reply with quote  
 Post subject: Re: time calculation
PostPosted: Sun Apr 29, 2012 10:31 pm 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
3 years later asking the same question and no answer exists yet :-p

Function MinDiff(xSQLDateTime as String) As Integer
dim base as new date
dim now as new date

now.SQLDateTime = xSQLDateTime

dim diffInSeconds as double = abs( now.totalseconds - base.totalseconds )
dim minsBetween as integer = diffInSeconds/60
Return minsBetween
End Function


Thanks to timhare :-)

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group