Dim MyDateTime As Long
Dim txtDate, txtTime As String
Dim Datepr, MyDate As Long
Dim Ndays as double
MyDateTime = DateTime.Now
DateTime.DateFormat = "M/d/yyyy" 'example: 12/28/2011
DateTime.TimeFormat="h:mm:ss a" 'example: 6:29:17 PM
txtDate=DateTime.Date(MyDateTime)
txtTime=DateTime.Time(MyDateTime)
Msgbox(txtDate & " " & txtTime,"")
Datepr = DateTime.DateParse("12/24/2011") + DateTime.TimeParse("6:29:17 PM")
'MyDate = DateTime.DateParse("12/28/2011") + DateTime.TimeParse("6:29:17 PM") 'You enter the current date and time manually here.
MyDate = DateTime.DateParse(txtDate) + DateTime.TimeParse(txtTime)
Ndays=Round2((MyDate - Datepr)/1000/3600/24,1)
Msgbox(Ndays,"")
'=======================================================
'calc dates
'-----------------------------
'1 day
Dim date1, date2, DateX, elapsed As Long
date1 = DateTime.DateParse(CalcDateIn) + DateTime.TimeParse(CalcTimeIn)
date2 = DateTime.DateParse(CalcDateOut) + DateTime.TimeParse(CalcTimeOut)
'------------------------
'CTImins is long(CalcTimeIn is String)
CTImins = (IncTimeInHour * 60) + IncTimeInMinute '(give total mins for hours plus mins)
'CTOmins is long(CalcTimeOut is string)
CTOmins = (IncTimeOutHour * 60) + IncTimeOutMinute'(give total mins for hours plus mins)
'---------------------------------------------
DateTime.DateFormat = "M/d/yyyy"
DateTime.TimeFormat = "HH:mm:ss"
Dim DateDOYin, DateDOYout As Int
Dim SomeDateIn, SomeDateOut As Long
SomeDateIn = DateTime.DateParse(CalcDateIn)
SomeDateOut = DateTime.DateParse(CalcDateOut)
DateDOYin = DateTime.GetDayOfYear(SomeDateIn)
DateDOYout = DateTime.GetDayOfYear(SomeDateOut)
Msgbox("STI-" & SomeDateIn & CRLF & "STO" & SomeDateOut & CRLF & "DOYin-" & DateDOYin & CRLF & "DOYout-" & DateDOYout, "OK")
'----------------------------------------------------------
If DateDOYin = DateDOYout AND CTImins = CTOmins Then
'same date/// start time is same as out time (Error) (tues 3pm - tues 3pm) (-0 hour)
InOutOK = False
Msgbox("Days are same OK, but start time & out time are the same. Go back and fix.", "OK")
'
Else If DateDOYin = DateDOYout AND CTImins < CTOmins Then
'same date/// start time BEFORE out time (Good) (tues 3pm - tues 4pm) (1 hour)
InOutOK = True
'
elapsed = date2 - date1
Else If DateDOYin = DateDOYout AND CTImins > CTOmins Then
'same date/// start time AFTER out time (Error) (tues 3pm - tues 2pm) (-1 hour)
InOutOK = False
Msgbox("Days are same OK, but start time is AFTER out time. Go back and fix.", "OK")
'
'-----------------------------------
Else If DateDOYin < DateDOYout AND CTImins < CTOmins Then
'In date BEFORE out date/// Start time BEFORE= out time (Error) (tues 3pm - wed 4pm) (25 hours)
InOutOK = False
Msgbox("You worked over 24 hours. Create 2 entries (1st entry until midnight & 2nd entry is after midnight). Go back and fix.", "OK")
'
Else If DateDOYin < DateDOYout AND CTImins >= CTOmins Then
'In date BEFORE out date/// Start time AFTER out time (tues 3pm - wed 2pm) (23 hours)
InOutOK = True
'
elapsed = (date2 - date1) + 24
'-----------------------------------
Else If DateDOYin > DateDOYout Then
'In date AFTER out date/// (Error)
InOutOK = False
Msgbox("Start date is AFTER end date. Go back and fix.", "OK")
'
End If
'--------------------------------------------------------------
If InOutOK = True Then
'--------------------------------------
seconds = Round(elapsed / 1000)
minutes = Floor(seconds / 60) Mod 60
hours = Floor(seconds / 3600)
days = Floor(hours / 24)
hours = hours Mod 24
seconds = seconds Mod 60
'----------------
'Put up dates
Label1803a.Text = CalcDateIn
Label1803b.Text = CalcDateOut
'----------------
'put up times
Label1803aa.Text = CalcTimeIn
Label1803bb.Text = CalcTimeOut
Label1803cc.Text = hours & " Hrs, " & minutes & " Mins"
Else
'----------------
'Put up dates
Label1803a.Text = "Error"
Label1803b.Text = "Error"
'----------------
'put up times
Label1803aa.Text = "Error"
Label1803bb.Text = "Error"
Label1803cc.Text = "Error"
End If
'====================================================================================
Sub Activity_Create(FirstTime As Boolean)
DateBetweenTwoDates("01/20/13", "22:00:00", "01/23/14", "08:12:34")
End Sub
Sub DateBetweenTwoDates(D1 As String, T1 As String, D2 As String, T2 As String)
Dim start, endTime, t As Long
start = DateTime.DateTimeParse(D1, T1)
endTime = DateTime.DateTimeParse(D2, T2)
Dim days, hours, minutes, seconds As Int
t = endTime - start
days = Floor(t / DateTime.TicksPerDay)
hours = Floor((t Mod DateTime.TicksPerDay) / DateTime.TicksPerHour)
minutes = Floor((t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute)
seconds = Floor((t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond)
Log("Days = " & days)
Log("Hours = " & hours)
Log("Minutes = " & minutes)
Log("Seconds = " & seconds)
End Sub
Erel, here are the results of my tests of your formula code for 2 dates. all had 00 for seconds. results are days, hours, mins, seconds. I you look at these you will see that the times are incorrect on some of these(and thus my issues with time calculations)
==========================
same day, same time
1/21/2013 3:01am
1/21/2013 3:01am
0,0,0,0 (correct)
========================
same day, later end time
1/21/2013 3:01am
1/21/2013 4:02am
0,1,1,0 (correct)
==========================
same day earlier end time
1/21/2013 3:01am
1/21/2013 2:02 am
-1, -1, -59, 0 (WRONG-IT'S THE SAME DAY. SHOULD BE 0,-1,-59,0)==========================
End day is earlier than start day
1/21/2013 3:00am
1/20/2013 2:00 am
-1, -1, 0,0 (CORRECT)
===============================
End day is earlier than start day
1/21/2013 3:01am
1/20/2013 3:01 am
0, 0, 0, 0 (Wrong, it's a day earlier- should be -1,0,0,0)
========================
End day is earlier than start day
1/21/2013 3:01am
1/20/2013 6:01 am
0,3,0,0(wrong, it's a day earlier. should be 0,21,0,0 )
==========================
End day is after start day
1/21/2013 3:01am
1/22/2013 6:04 am
0,3,3,0 (wrong, should be 1,3,3,0)
==========================
End day is after start day
1/21/2013 3:01am
1/22/2013 3:01 am
0,0,0,0 (wrong, should be 1,0,0,0)
==========================
End day is after start day
1/21/2013 3:01am
1/22/2013 2:01 am
-1, -1,0, 0 (correct)
==========================
Sub DateBetweenStartDateAndEndDate(D1 As String, T1 As String, D2 As String, T2 As String)
Dim start, endTime, t As Long
start = DateTime.DateTimeParse(D1, T1)
endTime = DateTime.DateTimeParse(D2, T2)
Dim days, hours, minutes, seconds As Int
t = Abs(endTime - start)
days = Floor(t / DateTime.TicksPerDay)
hours = Floor((t Mod DateTime.TicksPerDay) / DateTime.TicksPerHour)
minutes = Floor((t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute)
seconds = Floor((t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond)
If endTime < start Then
days = -days
hours = -hours
minutes = -minutes
seconds = -seconds
End If
Log("Days = " & days)
Log("Hours = " & hours)
Log("Minutes = " & minutes)
Log("Seconds = " & seconds)
End Sub
Something wrong with your code. You're getting different results then I'm getting. Can you post your code?
DateBetweenTwoDates(CalcDateIn, CalcTimeIn, CalcDateOut, CalcTimeOut)
Msgbox(CalcDateIn & CRLF & CalcTimeIn & CRLF & CalcDateOut & CRLF & CalcTimeOut, "OK")
'Put up dates
Label1803a.Text = CalcDateIn
Label1803b.Text = CalcDateOut
The input are strings as shown in the pictures (CalcDateIn, CalcTimeIn, CalcDateOut, CalcTimeOut). The actual format are shown in the pictures. Maybe that has something to do with it. Maybe the format had a 2/2/2012 and needs 02/02/2012? Heck if I know, I'm a beginner.
B4X:DateBetweenTwoDates(CalcDateIn, CalcTimeIn, CalcDateOut, CalcTimeOut) Msgbox(CalcDateIn & CRLF & CalcTimeIn & CRLF & CalcDateOut & CRLF & CalcTimeOut, "OK") 'Put up dates Label1803a.Text = CalcDateIn Label1803b.Text = CalcDateOut
The times input came from a input dialog (one for time and 1 for date). This code doesn't matter and they just give a string with the date and another string with the time (both for start and end). These strings are put into (CalcDateIn, CalcTimeIn, CalcDateOut, CalcTimeOut). You can see the input string on the pictures.
DateBetweenTwoDates(CalcDateIn, CalcTimeIn, CalcDateOut, CalcTimeOut)
Msgbox(CalcDateIn & CRLF & CalcTimeIn & CRLF & CalcDateOut & CRLF & CalcTimeOut, "OK")
Sub DateBetweenTwoDates(D1 As String, T1 As String, D2 As String, T2 As String)
Dim start, endTime, t As Long
start = DateTime.DateTimeParse(D1, T1)
endTime = DateTime.DateTimeParse(D2, T2)
Dim days, hours, minutes, seconds As Int
t = Abs(endTime - start)
days = Floor(t / DateTime.TicksPerDay)
hours = Floor((t Mod DateTime.TicksPerDay) / DateTime.TicksPerHour)
minutes = Floor((t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute)
seconds = Floor((t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond)
Log("Days = " & days)
Log("Hours = " & hours)
Log("Minutes = " & minutes)
Log("Seconds = " & seconds)
Msgbox("Days = " & days & CRLF & "Hours = " & hours & CRLF & "Minutes = " & minutes & CRLF & "Seconds = " & seconds, "OK")
End Sub
=========================================================================================
'----------------------------------------
'put today's date into current variables so when auser open up income, it always shows today's date
IncYearIn = TodayYear
IncMonthIn = TodayMonth
IncDayOfMonthIn = TodayDayOfMonth
IncDayStringIn = TodayDayString
IncDayNumIn = TodayDayNum
IncMMDDYYYYIn = TodayMMDDYYYY
IncComboIn = TodayCombo
'----------------------------------------------
IncYearOut = TodayYear
IncMonthOut = TodayMonth
IncDayOfMonthOut = TodayDayOfMonth
IncDayStringOut = TodayDayString
IncDayNumOut = TodayDayNum
IncMMDDYYYYOut = TodayMMDDYYYY
IncComboOut = TodayCombo
'--------------------------------------------
'put day and date on label
Label1701DateIn.text = IncDayStringIn & ", " & IncMMDDYYYYIn
Label1701DateOut.text = IncDayStringOut & ", " & IncMMDDYYYYOut
'-----------------------------------------
'Clear In time
IncTimeInHour = 0 '24 hour true time
IncTimeInHourB = 12 '12 hour
IncTimeInMinute = 00
IncTimeInMinuteString = "00"
IncTimeInAMPM = "AM"
'---------------------------------------------
'Clear Out time
IncTimeOutHour = 0 '24 hour true time
IncTimeOutHourB = 12 '12 hour
IncTimeOutMinute = 00
IncTimeOutMinuteString = "00"
IncTimeOutAMPM = "AM"
'---------------------------------------------------------------
'put into time adn date string for calc in case use doesnt change day or time
CalcTimeIn = IncTimeInHour & ":" & IncTimeInMinute & ":" & "00"
CalcTimeOut = IncTimeOutHour & ":" & IncTimeOutMinute & ":" & "00"
CalcDateIn = IncMonthIn & "/" & IncDayOfMonthIn & "/" & IncYearIn
CalcDateOut = IncMonthOut & "/" & IncDayOfMonthOut & "/" & IncYearOut
'---------------------------------------------
'Put variables into label
Label1702ClockIn.text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM 'default In time
Label1703ClockOut.text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM 'default out time
'=========================================================================================
Sub Button1701DateIn_Click
'---------------------------------------------
'show date dialog box in pop up box.
Dim RetDateIn As Int
DdIn.Year = DateTime.GetYear(DateTime.now)
DdIn.Month = DateTime.GetMonth(DateTime.now)
DdIn.DayOfMonth = DateTime.GetDayOfMonth(DateTime.now)
'-----------------------------
IncDayNumIn = DateTime.GetDayOfWeek(DdIn.DateTicks)
Select IncDayNumIn
Case 1
IncDayMDYIn = "Right Now, it is Sunday: " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
Case 2
IncDayMDYIn = "Right Now, it is Monday: " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
Case 3
IncDayMDYIn = "Right Now, it is Tuesday: " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
Case 4
IncDayMDYIn = "Right Now, it is Wednesday: " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
Case 5
IncDayMDYIn = "Right Now, it is Thursday: " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
Case 6
IncDayMDYIn = "Right Now, it is Friday: " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
Case 7
IncDayMDYIn = "Right Now, it is Saturday: " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
End Select
'---------------------------------------------------------
RetDateIn = DdIn.Show(IncDayMDYIn, "Start of Workday?", "Save", "", "", Bmp)
'============================================================================================
'change top line with new day and date
IncDayNumIn = DateTime.GetDayOfWeek(DdIn.DateTicks)
Select IncDayNumIn
Case 1
Label1701DateIn.text = ("Sunday, " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year)
IncDayStringIn = "Sunday"
Case 2
Label1701DateIn.text = ("Monday, " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year)
IncDayStringIn = "Monday"
Case 3
Label1701DateIn.text = ("Tuesday, " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year)
IncDayStringIn = "Tuesday"
Case 4
Label1701DateIn.text = ("Wednesday, " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year)
IncDayStringIn = "Wednesday"
Case 5
Label1701DateIn.text = ("Thursday, " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year)
IncDayStringIn = "Thursday"
Case 6
Label1701DateIn.text = ("Friday, " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year)
IncDayStringIn = "Friday"
Case 7
Label1701DateIn.text = ("Saturday, " & DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year)
IncDayStringIn = "Saturday"
End Select
'-----------------------------------------------------------------------
'copy over variables
IncYearIn = DdIn.Year
IncMonthIn = DdIn.Month
IncDayOfMonthIn = DdIn.DayOfMonth
IncMMDDYYYYIn = DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
IncComboIn = IncDayStringIn & ", " & IncMMDDYYYYIn
CalcDateIn = DdIn.Month & "/" & DdIn.DayOfMonth & "/" & DdIn.Year
'---------------------------------------------
End Sub
Sub Button1701DateOut_Click
'---------------------------------------------
'show date dialog box in pop up box.
Dim RetDateOut As Int
DdOut.Year = DateTime.GetYear(DateTime.now)
DdOut.Month = DateTime.GetMonth(DateTime.now)
DdOut.DayOfMonth = DateTime.GetDayOfMonth(DateTime.now)
'-----------------------------
IncDayNumOut = DateTime.GetDayOfWeek(DdOut.DateTicks)
Select IncDayNumOut
Case 1
IncDayMDYOut = "Right Now, it is Sunday: " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
Case 2
IncDayMDYOut = "Right Now, it is Monday: " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
Case 3
IncDayMDYOut = "Right Now, it is Tuesday: " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
Case 4
IncDayMDYOut = "Right Now, it is Wednesday: " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
Case 5
IncDayMDYOut = "Right Now, it is Thursday: " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
Case 6
IncDayMDYOut = "Right Now, it is Friday: " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
Case 7
IncDayMDYOut = "Right Now, it is Saturday: " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
End Select
'---------------------------------------------------------
RetDateOut = DdOut.Show(IncDayMDYOut, "Start of Workday?", "Save", "", "", Bmp)
'============================================================================================
'change top line with new day and date
IncDayNumOut = DateTime.GetDayOfWeek(DdOut.DateTicks)
Select IncDayNumOut
Case 1
Label1701DateOut.text = ("Sunday, " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year)
IncDayStringOut = "Sunday"
Case 2
Label1701DateOut.text = ("Monday, " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year)
IncDayStringOut = "Monday"
Case 3
Label1701DateOut.text = ("Tuesday, " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year)
IncDayStringOut = "Tuesday"
Case 4
Label1701DateOut.text = ("Wednesday, " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year)
IncDayStringOut = "Wednesday"
Case 5
Label1701DateOut.text = ("Thursday, " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year)
IncDayStringOut = "Thursday"
Case 6
Label1701DateOut.text = ("Friday, " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year)
IncDayStringOut = "Friday"
Case 7
Label1701DateOut.text = ("Saturday, " & DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year)
IncDayStringOut = "Saturday"
End Select
'-----------------------------------------------------------------------
'copy over variables
IncYearOut = DdOut.Year
IncMonthOut = DdOut.Month
IncDayOfMonthOut = DdOut.DayOfMonth
IncMMDDYYYYOut = DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
IncComboOut = IncDayStringOut & ", " & IncMMDDYYYYOut
CalcDateOut = DdOut.Month & "/" & DdOut.DayOfMonth & "/" & DdOut.Year
'---------------------------------------------
End Sub
Sub Button1702ClockIn_Click
'------------------------------------------
Td.Hour = IncTimeInHour 'put hour and time in so clock starts with current time input
Td.Minute = IncTimeInMinute
RetModify = Td.Show("What time did you clock in at?", "Start Time", "", "Cancel", "", Bmp)
'--------------------------------------------------
'Add time to variables
IncTimeInHour = Td.Hour 'new time user inputed
IncTimeInMinute = Td.Minute 'new minute user inputes
'-----------------------------------------
'set to 2 places always
IncTimeInMinuteString = NumberFormat2(IncTimeInMinute, 2, 0, 0, False) '2 digit left of decimal, 0 right of decimal
'------------------------------------------
'display correct hour
Select IncTimeInHour
Case 0
IncTimeInAMPM = "AM"
IncTimeInHourB = 12
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 1
IncTimeInAMPM = "AM"
IncTimeInHourB = 1
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 2
IncTimeInAMPM = "AM"
IncTimeInHourB = 2
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 3
IncTimeInAMPM = "AM"
IncTimeInHourB = 3
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 4
IncTimeInAMPM = "AM"
IncTimeInHourB = 4
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 5
IncTimeInAMPM = "AM"
IncTimeInHourB = 5
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 6
IncTimeInAMPM = "AM"
IncTimeInHourB = 6
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 7
IncTimeInAMPM = "AM"
IncTimeInHourB = 7
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 8
IncTimeInAMPM = "AM"
IncTimeInHourB = 8
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 9
IncTimeInAMPM = "AM"
IncTimeInHourB = 9
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 10
IncTimeInAMPM = "AM"
IncTimeInHourB = 10
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 11
IncTimeInAMPM = "AM"
IncTimeInHourB = 11
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
'---------------------------------------------------------
Case 12
IncTimeInAMPM = "PM"
IncTimeInHourB = 12
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 13
IncTimeInAMPM = "PM"
IncTimeInHourB = 1
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 14
IncTimeInAMPM = "PM"
IncTimeInHourB = 2
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 15
IncTimeInAMPM = "PM"
IncTimeInHourB = 3
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 16
IncTimeInAMPM = "PM"
IncTimeInHourB = 4
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 17
IncTimeInAMPM = "PM"
IncTimeInHourB = 5
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 18
IncTimeInAMPM = "PM"
IncTimeInHourB = 6
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 19
IncTimeInAMPM = "PM"
IncTimeInHourB = 7
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 20
IncTimeInAMPM = "PM"
IncTimeInHourB = 8
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 21
IncTimeInAMPM = "PM"
IncTimeInHourB = 9
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 22
IncTimeInAMPM = "PM"
IncTimeInHourB = 10
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 23
IncTimeInAMPM = "PM"
IncTimeInHourB = 11
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
Case 24
IncTimeInAMPM = "PM"
IncTimeInHourB = 12
Label1702ClockIn.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & IncTimeInAMPM
End Select
'--------------------------------------------------
'put into time for calc
CalcTimeIn = Td.Hour & ":" & Td.Minute & ":" & "00"
'---------------------------------------------
End Sub
Sub Button1703ClockOut_Click
'------------------------------------------
Td.Hour = IncTimeOutHour '24 hour format
Td.Minute = IncTimeOutMinute
RetModify = Td.Show("What time did you clock out at?", "End Time", "Save", "", "", Bmp)
'------------------------------------------
'Add time to variables
IncTimeOutHour = Td.Hour 'new hour from user
IncTimeOutMinute = Td.Minute 'new mins from user
'-----------------------------------------
'set to 2 places always
IncTimeOutMinuteString = NumberFormat2(IncTimeOutMinute, 2, 0, 0, False) '2 digit left of decimal, 0 right of decimal
'------------------------------------------
'display correct hour
Select IncTimeOutHour
Case 0
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 12
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 1
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 1
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 2
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 2
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 3
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 3
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 4
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 4
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 5
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 5
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 6
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 6
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 7
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 7
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 8
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 8
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 9
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 9
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 10
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 10
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 11
IncTimeOutAMPM = "AM"
IncTimeOutHourB = 11
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
'---------------------------------------------------------
Case 12
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 12
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 13
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 1
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 14
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 2
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 15
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 3
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 16
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 4
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 17
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 5
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 18
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 6
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 19
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 7
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 20
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 8
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 21
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 9
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 22
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 10
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 23
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 11
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
Case 24
IncTimeOutAMPM = "PM"
IncTimeOutHourB = 12
Label1703ClockOut.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & IncTimeOutAMPM
End Select
'--------------------------------------------------
'put into time for calc
CalcTimeOut = Td.Hour & ":" & Td.Minute & ":" & "00"
'---------------------------------------------
End Sub
DateBetweenTwoDates(CalcDateIn, CalcTimeIn, CalcDateOut, CalcTimeOut)
Msgbox(CalcDateIn & CRLF & CalcTimeIn & CRLF & CalcDateOut & CRLF & CalcTimeOut, "OK")
'Put up dates
Label1803a.Text = CalcDateIn
Label1803b.Text = CalcDateOut
'----------------
'put up times
Label1803aa.Text = IncTimeInHourB & ":" & IncTimeInMinuteString & " " & IncTimeInAMPM
Label1803bb.Text = IncTimeOutHourB & ":" & IncTimeOutMinuteString & " " & IncTimeOutAMPM
Label1803cc.Text = "(" & hours & " Hrs, " & minutes & " Mins)"
Msgbox(Floor(59.5),"") 'returns 59
Msgbox(Floor(-59.5),"") 'returns -60
You cannot use Erel's code if the end date is earlier than the start date because the calculations make use of the Floor function. Here is an example:
If you want to use a start date bigger than end date you need to use the Absolute value like this: t = Abs(e - s)B4X:Msgbox(Floor(59.5),"") 'returns 59 Msgbox(Floor(-59.5),"") 'returns -60
I did see post #23. I was actually corroborating it. Could you concisely tell us what the problem is with one simple example. I have a routine I use to calculate days, hrs, mn, etc. I would like to verify my calculations.That's not the problem. See my post #23.
I did see post #23. I was actually corroborating it. Could you concisely tell us what the problem is with one simple example. I have a routine I use to calculate days, hrs, mn, etc. I would like to verify my calculations.
'Returns the ticks value of the given date (the time will be 00:00:00).
Sub SetDate(Years As Int, Months As Int, Days As Int) As Long
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?