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

Thread: Date/Time

  1. #1
    Join Date
    Jun 2000
    Location
    India
    Posts
    12

    Date/Time


    Dim dteValue as date

    dteValue=date

    "SELECT CODE FROM PLAN WHERE
    (DATEVALUE(""" dteValue """) BETWEEN
    [StartDate] AND [EndDate])"





    This query gives me all the codes in which Today's Date falls between their StartDate and EndDate.

    Now, i have two more fields [StartTime] and [EndTime]. So, I want to write a query that gives me all the codes in which Today's Date including Time falls between their StartDate + StartTime and EndDate + EndTime.

    I have to write this query for MS Access, in Visual Basic.

    The query I have written is as follows:


    Dim sDate as string

    sDate=dteToday & FORMAT(time,hh:mm)

    "SELECT CODE FROM PLAN WHERE
    (DateValue(""" & sDate & """)] BETWEEN
    [StartDate] & [StartTime] AND
    [EndDate] & [EndTime])"





    The above query works but does not give right value because DateValue function excludes the Time part from Date. So, Please suggest the function which solves
    the purpose or
    another way of writing this.

    Thanks



  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Date/Time

    DOn't use function DateValue.
    dim MyaData as Date
    and use it instead of sDate.
    Instead if quotes around date use #

    "SELECT CODE FROM PLAN WHERE #" & MyDate & "# BETWEEN " & StartDate & StartTime & " AND " & EndDate & EndTime





    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Date/Time

    Make sure to give the statement proper formatting. In your example, if the date was 01/07/2001 and the time was 11:00, you statement would read 01/07/200111:00, which will fail. You must leave a space between date and time, and should always give the complete time (including seconds). You statement should look like 01/07/2001 11:00:00

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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