PRB: DateValue Does Not Return Time Information

Last reviewed: January 6, 1998
Article ID: Q178554
The information in this article applies to:
  • Collaboration Data Objects (CDO), version 1.2
  • Microsoft Active Server Pages, versions 1.0, 1.0b
  • Microsoft Visual Basic Standard and Enterprise Editions for Windows, version 5.0

SYMPTOMS

The DateValue function does not appear to use time as part of its filter criteria when filtering appointments.

CAUSE

If the date argument includes time information, DateValue does not return the time. However, if the date includes invalid time information (such as "89:98"), an error occurs.

RESOLUTION

If you want to apply a filter to your AppointmentItems collection that includes time as part of either the StartTime or EndTime, do not use the DateValue function.

STATUS

This behavior is by design.

MORE INFORMATION

When filtering an AppointmentItem collection you need to use code similar to the following:

   Set objAppointmentFilterField1 = _
     objAppointmentFilter.Fields.Add(ActMsgPR_START_DATE, EndTime)
   Set objAppointmentFilterField2 = _
     objAppointmentFilter.Fields.Add(ActMsgPR_END_DATE, StartTime)

NOTE: EndTime and StartTime are in vbDate format.

If you want to filter for all appointments that start after 10:00 AM on January 1, 1998, the following line will not work because DateValue does not return the time value:

   Set objAppointmentFilterField1 = _
     objAppointmentFilter.Fields.Add(ActMsgPR_START_DATE, _
     DateValue("1/2/97"))
   Set objAppointmentFilterField1 = _
     objAppointmentFilter.Fields.Add(ActMsgPR_END_DATE, _
     DateValue("1/1/98 10:00 AM"))

The code above returns all the appointments on January 1, 1998, instead of the appointments for 10:00 AM.

The proper way to use a time filter is to employ one of the following two examples:

  • Set your EndTime and StartTime variables as vbDate and pass them as the second parameter to the appropriate statements:

          StartTime = #1/1/98 10:00 AM#
          EndTime = #1/2/98#
    

          Set objAppointmentFilterField1 = _
    
            objAppointmentFilter.Fields.Add(ActMsgPR_START_DATE, EndTime)
          Set objAppointmentFilterField2 = _
            objAppointmentFilter.Fields.Add(ActMsgPR_END_DATE, StartTime)
    
       -or-
    
    
  • Set your EndTime and StartTime variables as strings and pass them as the second parameter to the appropriate set statements:

          StartTime = "1/1/98 10:00 AM"
          EndTime = "1/2/98"
    

          Set objAppointmentFilterField1 = _
    
            objAppointmentFilter.Fields.Add(ActMsgPR_START_DATE, EndTime)
          Set objAppointmentFilterField2 = _
            objAppointmentFilter.Fields.Add(ActMsgPR_END_DATE, StartTime)
    
    

REFERENCES

For more information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q178508
   TITLE     : HOWTO: Write a VB MessageFilter for Your Appointment
               Collection

Microsoft Visual Basic Online: DateValue

Keywords          : cdo
Version           : WINDOWS:1.2,5.0; WINNT:1.0,1.0b
Platform          : WINDOWS winnt
Issue type        : kbprb


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 6, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.