Date and Time comparison


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Date and Time comparison

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Posts
    2

    Date and Time comparison

    I need to know how to compare the date of an appointment with the time the appointment is scheduled for so that if the time is = to a time on the same dat it will not let you enter it.

  2. #2
    Join Date
    Feb 2005
    Posts
    46
    If Format(Date1, "mm/dd/yyyy") = Format(Date2, "mm/dd/yyyy") Then
    If Format(Time1, "hh:mm:ss") = Format(Time2, "hh:mm:ss") Then
    'Both appointments are at the same time
    End If
    End If

    Does that help??

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Why not simply:
    If Date1 = Date2 Then...? ;-)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  4. #4
    Join Date
    Feb 2005
    Posts
    2
    Thanks your suggestion worked out well for me...


    Quote Originally Posted by rtwitty
    I need to know how to compare the date of an appointment with the time the appointment is scheduled for so that if the time is = to a time on the same dat it will not let you enter it.

    ok this is how it looks in the record: (This is Access 2000 by the way)


    (appointmentdate set by calendar control)

    appointmentdate Appointmenttime
    record 1 2/8/2005 7:30 AM wrong
    record 2 2/8/2005 7:30 AM

    these are the two record fields. I can't have an appointment scheduled at the same time, on the same date. If the date changes, then the time can remain, but if the date is the same for both records then the time must change.

    (appointmentdate set by calendar control)

    appointmentdate Appointmenttime
    record 1 2/7/2005 7:30 AM right
    record 2 2/8/2005 7:30 AM

    (appointmentdate set by calendar control)

    appointmentdate Appointmenttime
    record 1 2/8/2005 7:30 AM right
    record 2 2/8/2005 7:45 AM

    is there a macro or vb code that can check this when they type it in?
    Last edited by rtwitty; 02-24-2005 at 04:52 PM. Reason: more clear

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I recommend storing the date and time in a single field. Then add a unique index on the date/time field; Access will throw an error if you try to schedule two appointments at the same time.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center