CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2010
    Posts
    3

    Dates Comparison

    Hi, I have access databse and the field name for the date is "AddmissionDate" and the date is in this format "13 01 2017" which is saved in the database.

    when I am selecting two dates in DTP1 and DTP2 for the records to check between two dates the format is like this "DateTimePicker1= # 1/13/2016 12:00:00 AM #" "DateTimePicker2= # 1/29/2017 12:00:00 AM #"

    I am using this query
    da = New OleDbDataAdapter("SELECT * FROM Addmission WHERE AddmissionDate BETWEEN #" & DateTimePicker1.Value & "# And #" & DateTimePicker2.Value & "#", con)

    I know the dates return the DTP1 and DTP2 are not in correct format , But can you tell what should I do to solve the problem and get the correct query between two dates.

    Thanks

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Dates Comparison

    You would need to use the Format method to put the date in the correct format.

    The way you show it as being in the database makes me think it is in a text field rather than a date field, either that or you have some formating in Access that is showing you the date that way but that is not the way it would be in the system.

    If it is a text field then you would not use the # signs as delimiters, you would need to use ' instead.
    If it truly is a date field then I would expect it to be in the standard US format of mm/dd/yyyy
    Always use [code][/code] tags when posting code.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Dates Comparison

    Why not compare the date as a DateTime object rather than a string? Then it doesn't matter what format the string representation of the DateTime is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured