Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m adding a day from Calender into List view , if i Click another Day from Calendar Its Should not be From the Same Week Which were there in the List view
How can i do it
plz help me Out
Posted
Updated 13-Jun-11 19:26pm
v2

1 solution

Assuming
variable d1 has the date (existing)
variable d2 has the new date entered

here's a piece of code to check

VB
Dim i As Integer
i = DateDiff("d", DateAdd("d", -(Weekday(d1)), d1), d2)
If i < 0 Or i > 6 Then
    MsgBox "Error"
End If


Too much in one line?
The idea is to get the date of the first weekday of d1 & then to check if d2 is within 7 days (0-6) of d1

I've chopped it down here
Weekday(d1)
(step 1)gets the weekday (0=sun to 7=sat)
DateAdd("d", -(step1), d1)
(step 2) gets the date of the week's beginning
DateDiff("d", step2, d2)
(step 3) gets the difference (how far is d2 from the week's beginning)

Then you check if it's within 7 days
 
Share this answer
 
Comments
Nagy Vilmos 14-Jun-11 9:01am    
Spot on.
strogg 16-Jun-11 8:54am    
lol, just happened to see y'r profile. It's too cool. I think i'm on the same road - almost there :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900