Android Question [Solved] How to get the first Saturday in a month

Discussion in 'Android Questions' started by asales, Feb 24, 2015.

  1. asales

    asales Well-Known Member Licensed User

  2. Erel

    Erel Administrator Staff Member Licensed User

    Dim t As Long = DateTime.DateParse("02/24/2015")
    Dim sat As Long = FirstDayOfMonth(7DateTime.GetMonth(t), DateTime.GetYear(t)) '7 for saturday

    Sub FirstDayOfMonth(Day As Int, Month As Int, Year As Int) As Long
    Dim s As Long = DateUtils.SetDate(Year, Month, 1)
    Dim d As Int = DateTime.GetDayOfWeek(s)
    Dim p As Period
       p.Days = (Day + 
    7 - d) Mod 7
    Return DateUtils.AddPeriod(s, p)
    End Sub
    I only tested it with the values in your question. Make sure to test it more.
    asales and eurojam like this.
  3. asales

    asales Well-Known Member Licensed User

    Thanks Erel. I tried with several dates and works fine.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice