Android Question WeekNum in the past

parijs

Active Member
Licensed User
Longtime User
Hi,

Is it possible to get a week number in the past.
Sample: the week number of 06/02/2013
 

LucaMs

Expert
Licensed User
Longtime User
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
Log("Week: " & WeekNumber("06/02/2013"))

Sub WeekNumber(SomeDate As String) As Int
    Dim SomeDateTicks As Long = DateTime.DateParse(SomeDate)
    Dim SomeDateYear As Int = DateTime.GetYear(SomeDateTicks)
    Dim StartDate As Long = DateTime.DateParse("01/01/" & SomeDateYear)
    Dim p As Period = PeriodBetweenInDays(StartDate, SomeDateTicks)
    Dim Weeks As Int = p.Days / 7 + 1
    Return Weeks
End Sub

"Import" DateUtils library
 
Last edited:
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
Log("Week: " & WeekNumber("06/02/2013"))

Sub WeekNumber(SomeDate As String) As Int
    Dim SomeDateTicks As Long = DateTime.DateParse(SomeDate)
    Dim SomeDateYear As Int = DateTime.GetYear(SomeDateTicks)
    Dim StartDate As Long = DateTime.DateParse("01/01/" & SomeDateYear)
    Dim p As Period = PeriodBetweenInDays(StartDate, SomeDateTicks)
    Dim Weeks As Int = p.Days / 7 + 1
    Return Weeks
End Sub

"Import" DateUtils library

Thats too much code and operations for something really simple. You can do this without any external lib and only in 2 lines of code

B4X:
DateTime.DateFormat = "w"
Log("Week: " & DateTime.Date(DateTime.DateParse("06/02/2013")))
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Return Weeks
He does not want to know the weeks between two dates. He want to get the "WeekNo in the Year (1-52)"
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
B4X:
DateTime.DateFormat = "w"
Log("Week: " & DateTime.Date(DateTime.DateParse("06/02/2013")))

coincidentally, that code results in week #6 .. which is correct. But change the date and the result will always be the 'Day' portion.

maybe this..
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
Dim tempDate As Long = DateTime.DateParse("06/02/2013")
DateTime.DateFormat = "w"
Log("Week: " & DateTime.Date(tempDate))
 
Upvote 0
Top