|
-
Oct 15th, 2008, 06:38 PM
#1
Thread Starter
Fanatic Member
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!
-
Oct 15th, 2008, 08:50 PM
#2
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.
-
Oct 16th, 2008, 01:40 AM
#3
Thread Starter
Fanatic Member
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.
-
Oct 16th, 2008, 02:57 AM
#4
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
-
Oct 16th, 2008, 06:05 AM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|