Has anyone a good method of getting the dates (as longs) for the start (Monday at 00:00) and end (Sunday at 00:00) of last week? I'm using these in an SQL query to get records that were created anytime last week.
I have been trying the following but it always seems to give me a start date of 24/3 at 23:00.
Thanks for any help.
I have been trying the following but it always seems to give me a start date of 24/3 at 23:00.
B4X:
Dim now, thisday, midnight, swlong, sdlong, edlong as long
Dim daynum, numdays as int
Dim thisday as string
now = DateTime.now
thisday = DateTime.Date(now)
midnight = DateTime.DateParse(thisday)
daynum = DateTime.GetDayOfWeek(now)
If daynum = 1 Then
numdays = 6
Else
numdays = daynum - 2
End If
swlong = midnight - numdays*DateTime.TicksPerDay ' start of this week
SDlong = (swlong+1) - 7*DateTime.TicksPerDay ' start of last week
EDlong = swlong - 1 ' end of last week
Thanks for any help.