[AccessD] Forcing a date calculation

Gustav Brock Gustav at cactus.dk
Thu Sep 1 02:38:42 CDT 2005


Hi Chris

We have a generic function (well two functions) for this purpose:

<code>

Function DateNextWeekday( _
  ByVal datDate As Date, _
  Optional ByVal bytWeekday As Byte = vbMonday) _
  As Date

' Returns the date of the next weekday, as spelled in vbXxxxday,
following datDate.
' 2000-09-06. Cactus Data ApS, CPH.
    
  ' No special error handling.
  On Error Resume Next
  
  DateNextWeekday = DateAdd("d", 7 - (WeekDay(datDate, bytWeekday) -
1), datDate)
    
End Function

Function DatePrevWeekday( _
  ByVal datDate As Date, _
  Optional ByVal bytWeekday As Byte = vbMonday) _
  As Date

' Returns the date of the previous weekday, as spelled in vbXxxxday,
prior to datDate.
' 2000-09-06. Cactus Data ApS, CPH.
    
  ' No special error handling.
  On Error Resume Next
  
  DatePrevWeekday = DateAdd("d", 1 - WeekDay(datDate, bytWeekday),
datDate)
    
End Function

</code>

As Stuart mentions, given the Sunday you can easily find the Monday
before. 
It's a matter of taste, but I prefer to use the Date functions whenever
possible, thus:

  datSundayPrevious = DatePrevWeekday(Date, vbSunday)
  datMondayBefore = DateAdd("d", -6, datSundayPrevious)

/gustav

>>> dc8 at btinternet.com 01-09-2005 00:00 >>>
All,

I have a form that users are supposed to enter a start date, always a
Monday
and an end date, always the Sunday after.

However, they seem completely unable to enter these dates correctly so
I am
trying to see if there is a way to force a date into the system using
Date()
and then going back to the previous Sunday and then working out the
Monday
prior to that.

So, 31 August 2005 would go back to Sunday 28th August 2005 and I would
then
subtract days to get Monday 22 August 2005.

Could anybody give me a pointer on if this is possible as the data
being
returned currently is normally incorrect and this is causing more than
a few
headaches !!

Thanks in advance,

Chris Swann




More information about the AccessD mailing list