Hi guys,
DateTime.Time(DateTime.Now is showing the time now,
How can I do something (Log("OFF")) if time is for example > 22:00 ?
it is my try
also I need to remove seconds just want to see hour and minutes
B4X:
ButtonTimeNow.Text=DateTime.Time(DateTime.Now)
Log(DateTime.TimeZoneOffset)
Log(DateTime.Time(DateTime.Now))
If DateTime.Time(DateTime.Now) > "22:18:00" Then
Log("OFF")
End If
it does not make any sense to me. can you explain exactly what you want to archive like when should the OFF be shown.
between what time? between 16:18 to 7:15 ?
ok, What I need is: the restaurant will be closed between 21:30 until 10:00
then people can not make orders using our mobile-App, when the restaurant is closed.
Actually the manager have to click a button in our MasterApp in the cafe,
but sometimes they forgot to click the button to close the option to receive orders,
This is why I want an automatic option.
I tested your code just between minutes, example 19:58 and 20:02 and it does work using:
(work means: I see the log OFF or ON when the condition is true)
B4X:
Dim OffHour1 = 19, OffMinute1 = 19, OffHour2 = 19, OffMinute2 = 21 As Int
Dim nowTime As Long = (DateTime.GetHour(DateTime.Now)*DateTime.TicksPerHour)+(DateTime.GetMinute(DateTime.Now)*DateTime.TicksPerMinute)
Dim offTime1 As Long = (DateTime.TicksPerHour*OffHour1)+(DateTime.TicksPerMinute*OffMinute1)
Dim offTime2 As Long = (DateTime.TicksPerHour*OffHour2)+(DateTime.TicksPerMinute*OffMinute2)
If nowTime > offTime1 And nowTime < offTime2 Then
Log(DateTime.Time(DateTime.Now))
Log("OFF")
Else
Log(DateTime.Time(DateTime.Now))
Log("ON")
End If
but does not work using OR or AND in this code:
B4X:
Dim OffHour1 = 18, OffMinute1 = 13, OffHour2 = 19, OffMinute2 = 16 As Int
Dim nowTime As Long = (DateTime.GetHour(DateTime.Now)*60)+DateTime.GetMinute(DateTime.Now)
Dim offTime1 As Long = (OffHour1*60)+OffMinute1
Dim offTime2 As Long = (OffHour2*60)+OffMinute2
If nowTime > offTime1 And nowTime < offTime2 Then
Log(DateTime.Time(DateTime.Now))
Log("OFF")
Else
Log(DateTime.Time(DateTime.Now))
Log("ON")
End If
of course, maybe I'm testing wrong... will do more tests soon..
thanks @ilan
Dim yy As Int = DateTime.GetYear(DateTime.Now)
Dim mm As Int = DateTime.GetMonth(DateTime.Now)
Dim dd As Int = DateTime.GetDayOfMonth(DateTime.Now)
Dim StartTime, EndTime As Long
StartTime = DateUtils.SetDateAndTime(yy, mm, dd, 10, 00, 0)
EndTime = DateUtils.SetDateAndTime(yy, mm, dd, 21, 30, 0)
If InBetween(StartTime, EndTime) Then
Log("We can take order now")
End If
Dim OffHour1 = 18, OffMinute1 = 50, OffHour2 = 13, OffMinute2 = 16 As Int
Dim nowTime As Long = (DateTime.GetHour(DateTime.Now)*60)+DateTime.GetMinute(DateTime.Now)
Dim offTime1 As Long = (OffHour1*60)+OffMinute1
Dim offTime2 As Long = (OffHour2*60)+OffMinute2
If nowTime > offTime1 Or nowTime < offTime2 Then
Log(DateTime.Time(DateTime.Now))
Log("OFF")
Else
Log(DateTime.Time(DateTime.Now))
Log("ON")
End If
Dim yy As Int = DateTime.GetYear(DateTime.Now)
Dim mm As Int = DateTime.GetMonth(DateTime.Now)
Dim dd As Int = DateTime.GetDayOfMonth(DateTime.Now)
Dim StartTime, EndTime As Long
StartTime = DateUtils.SetDateAndTime(yy, mm, dd, 10, 00, 0)
EndTime = DateUtils.SetDateAndTime(yy, mm, dd, 21, 30, 0)
If InBetween(StartTime, EndTime) Then
Log("We can take order now")
End If
From your description I got that you don't need to consider time zones and similar time related problems.
But, since you necessarily have a server where orders are sent, why not letting the server itself open/close the virtual shop (i.e. accept orders)?
This way you don't risk that a user could manually alter its local time and send an order when the shop is closed.