Android Question Between two hours

Discussion in 'Android Questions' started by migrec, Sep 9, 2015.

  1. migrec

    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:
    Code:
    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?
     
  2. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    Try using:

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

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

    - Colin
     
    Last edited: Sep 10, 2015
    migrec likes this.
  3. Ed Brown

    Ed Brown Active Member Licensed User

    Hello @migrec

    Try this
    Code:
    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
     
    mangojack and migrec like this.
  4. migrec

    migrec Member Licensed User

    Thank you both :)
    I used Ed's code and it works perfect.
     
  5. Ed Brown

    Ed Brown Active Member Licensed User

    You're welcome.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice