Results 1 to 2 of 2

Thread: Date Range Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Posts
    94

    Date Range Problem

    Hello Friends,

    I've designed a form which uses two DTPicker Control to select data of particular range. I want to display List of students enrolled in the period selected. I've written following code for that :

    VB Code:
    1. Dim dStartDate As Date
    2.     Dim dEndDate As Date
    3.     dStartDate = Format(dtpFrom.Value, "dd/MM/yyyy")
    4.     dEndDate = Format(dtpTo.Value, "dd/MM/yyyy")
    5.     With crStudList
    6.         .Connect = strConn
    7.         .SelectionFormula = "{tblStudent.RegistrationDate}>=datevalue(#" & dStartDate & "#) and {tblStudent.RegistrationDate}<=datevalue(#" & dEndDate & "#)"
    8. '        .SelectionFormula = "{tblStudent.RegistrationDate}>= DateValue (" & dtpFrom.Value & ") and {tblStudent.RegistrationDate}<= DateValue(" & dtpTo.Value & ")"
    9.         .ReportFileName = App.Path & "\reports\StudentList.rpt"
    10.         .ReportTitle = "Student List"
    11.         .WindowTitle = "Student List"
    12.         .WindowState = crptMaximized
    13.         .Destination = crptToWindow
    14.         .Action = 1
    15.     End With

    where i want to display students registered between dStartDate and dEndDate. If i select start date as 01/02/2006 and end date as 28/02/2006 then its giving students registered in january also. But if i give 02/01/2006 and 28/02/2006 its giving correct result. I tried

    VB Code:
    1. crStudList.SelectionFormula = "{tblStudent.RegistrationDate}>=datevalue(#" & dStartDate & "#) and {tblStudent.RegistrationDate}<=datevalue(#" & dEndDate & "#)"

    but no difference and getting same report. plz help me. I tried lot but not getting solution. Any quick help will be appreciated.

    thx in advance

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Date Range Problem

    When a date variable is converted to a string, the Regional Settings are used which may cause the dd/mm/yyyy format you set to be changed.

    You are always better off using a non ambiguous date format like dd-MMM-yyyy.

    Try changing the two Date variables to String variables and use the above format.

    Dim dStartDate As String
    Dim dEndDate As String

    dStartDate = Format(dtpFrom.Value, "dd-MMM-yyyy")
    dEndDate = Format(dtpTo.Value, "dd-MMM-yyyy")

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