Results 1 to 5 of 5

Thread: check if date is on birthday week

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Red face check if date is on birthday week

    Hi,

    MS Access 2003: I'd like to make a query / VBA code that checks if a given date falls in the same calendar week as the person birthday (consider a week starts on Sunday and ends on Saturday).

    for example: lets say my birthday is 18/10/2008 (so its coming this friday), and i want to check if the date 13/10/2008 falls on my birthday week then its true...

    Thanks!

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: check if date is on birthday week

    The simplest way is using DateDiff() with interval "ww"
    Code:
    w = DateDiff("ww", BirthDay, aDate, vbSunday)
    If w = 0 then aDate and BirthDay are in the same week that starts on Sunday.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Re: check if date is on birthday week

    I'm not checking that the certain date actually happens on the week of my birth, but rather on the week of my birthday (so every year is ok, not just the my birth year)....

    I guess what could work is to find the dates of Sunday, and of Saturday of the aDate, and then to compare the day and month of the birth date to this Sunday- Saturday range.

    Question is how to check that the birthday (day and month) are inside this range of week start to week end (considering cases like end of the year)

    Any ideas?
    Last edited by bambo; Oct 16th, 2008 at 02:07 AM.

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: check if date is on birthday week

    Is this what you want?

    Code:
    Sub FindWeekNo()
    'Change this date to check the week no
    'Insert the date as # 13 / 10 /2008#
    'Depending upon the system date and time it
    'will automatically readjust as shown below
    strdate = #10/13/2008#
    
    week_no = "Week " & Int((13 + Day(strdate) - Weekday(strdate)) / 7)
    
    MsgBox week_no
    
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: check if date is on birthday week

    Test this:
    Code:
    Function WOB(aDate As Date, DOB As Date, ThisBD As Date) As Integer
        ThisBD = DateSerial(Year(aDate), Month(DOB), Day(DOB))
        WOB = DateDiff("ww", ThisBD, aDate, vbSunday)
        If Abs(WOB) >= 51 Then
            ThisBD = DateAdd("yyyy", Sgn(WOB), ThisBD)
            WOB = DateDiff("ww", ThisBD, aDate, vbSunday)
        End If
    End Function
    Returns 0 if aDate and ThisBD are in the same week that starts on Sunday.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width