Android Question Adding x amount of minutes to a time held in a label.text field

Colin Evans

Active Member
Licensed User
Longtime User
Hi, I have a screen with a number of times displayed, read in from an excel spreadsheet but I need to add x amount of minutes to each time held in various label.text's, could anyone help point me in the right direction as I'm getting fairly confused how to achieve the desired result
i.e.

Day1 In Time: 10:35
Day1 Out Time: 12:15
Day2 In Time: 11:15
Day2 Out Time: 14:58

In this case I want to add seven minutes to each field before its displayed, so my display should read

Day1 In Time: 10:42
Day1 Out Time: 12:22
Day2 In Time: 11:22
Day2 Out Time: 15:05

Hope that makes sense and someone can help
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim timestrold As String = "10:35"
    Log("Time old (String): "&timestrold)
    Log("Time new: "&addminutes(timestrold,7))
End Sub
Sub addminutes(oldtime As String, minutes As Int) As String
    Dim oldtimeformat As String = DateTime.TimeFormat
    'Log(DateTime.DateFormat)
    'Log(DateTime.Date(DateTime.Now))
    'Log(DateTime.TimeFormat)
    'Log(DateTime.Time(DateTime.Now))
    DateTime.TimeFormat = "HH:mm"
    Dim dateold As Long = DateTime.DateTimeParse(DateTime.Date(DateTime.Now),oldtime)
    Dim p As Period
    p.Initialize
    p.Minutes = minutes
    
    Dim datenew As Long = DateUtils.AddPeriod(dateold,p)
    Dim timereturn As String = DateTime.Time(datenew)
    'Log("Time new: "&timereturn)
    DateTime.TimeFormat = oldtimeformat
    Return timereturn
End Sub


 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…