B4J Question Determine the current week in ticks or as a date

strupp01

Active Member
Licensed User
Longtime User
I want to determine the current week (start and end) as date or in ticks for start date and end date. Same for the previous week.

Example: Current Week Start: Mo 28.08.2017 End: Sun 03.09.2017
last week Start: Mo 21.08.2017 End: Sun 27.08.2017

How can I determine the start and end of a week?
 

Informatix

Expert
Licensed User
Longtime User
With the jCalendar library:
B4X:
'Start of week
Cal.InitializeToNow
Cal.Set(Cal.DAY_OF_WEEK, Cal.MONDAY)
Log(Cal.FormatWithStyles(Cal.FORMAT_STYLE_SHORT, Cal.FORMAT_STYLE_NO_TIME, Cal.LOCALE_ENGLISH))

'End of week
Cal.Set(Cal.DAY_OF_WEEK, Cal.SUNDAY)
Log(Cal.FormatWithStyles(Cal.FORMAT_STYLE_SHORT, Cal.FORMAT_STYLE_NO_TIME, Cal.LOCALE_ENGLISH))

'Alternative method:
'Start of week
Cal.InitializeToNow
Cal.Add(Cal.DAY_OF_MONTH, Cal.MONDAY - Cal.DAY_OF_WEEK + 1)
Log(Cal.FormatWithStyles(Cal.FORMAT_STYLE_SHORT, Cal.FORMAT_STYLE_NO_TIME, Cal.LOCALE_ENGLISH))

'End of week
Cal.InitializeToNow
Cal.Add(Cal.DAY_OF_MONTH, Cal.MONDAY - Cal.DAY_OF_WEEK + 7)
Log(Cal.FormatWithStyles(Cal.FORMAT_STYLE_SHORT, Cal.FORMAT_STYLE_NO_TIME, Cal.LOCALE_ENGLISH))

Replace Cal.MONDAY by Cal.SUNDAY if you want to begin the week on sunday in the alternative method.
 
Last edited:
Upvote 0
Top