Android Question Between two hours

migrec

Member
Licensed User
It's a simple question (not enough simple for me it seem)
I want to change WelcomLabels text between a few time stamps, like this:
B4X:
DateTime.TimeFormat = "HH:mm"
    Log(DateTime.Time(DateTime.Now))
    If DateTime.now > DateTime.TimeParse("05:00") AND DateTime.Now < DateTime.TimeParse("09:59") Then
       WelcomeLabel.Text = "Morgon"
    Else If DateTime.Now > DateTime.TimeParse("10:00") AND DateTime.Now < DateTime.TimeParse("17:59") Then
       WelcomeLabel.Text = "Dag"
    Else If DateTime.Now > DateTime.TimeParse("18:00") AND DateTime.Now < DateTime.TimeParse("21:59") Then
       WelcomeLabel.Text = "Kväll"
    Else If DateTime.Now > DateTime.TimeParse("22:00") AND DateTime.Now < DateTime.TimeParse("04:59") Then
       WelcomeLabel.Text = "Natt"
    End If
But it's not working, because I don't know how to write it properly... Can anyone correct me?
 

Computersmith64

Well-Known Member
Licensed User
Try using:

B4X:
DateTime.Timeparse(DateTime.Time(DateTime.Now))
instead of:

B4X:
DateTime.Now
Also you need to format your time string like "##:##:##"

- Colin
 
Last edited:

Ed Brown

Active Member
Licensed User
Hello @migrec

Try this
B4X:
    Dim Msg As String = "Natt"
    Dim ThisHour As Int = DateTime.GetHour(DateTime.Now)
    Select True
        Case ThisHour < 5        ' do nothing as we have defaulted the msg to cater for (> 22 AND < 5)
        Case ThisHour < 10
            Msg = "Morgon"
        Case ThisHour < 18
            Msg = "Dag"
        Case ThisHour < 22
            Msg = "Kväll"
    End Select
   
    WelcomeLabel.Text = Msg
 
Top