Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2003
    Posts
    2

    Question Unanswered: silly problem with the Date$ function

    im trying to programme a button to check the date before carrying out the click procedure. the code is very simplistic and im totally confused as to why it won't work! here's the code:
    -----------------------------------------------------------------------------------
    Private Sub neworder2()
    [click event for NEWORDER carries on here]
    End Sub

    Private Sub Frm_switch_new_orders_NEWORDER_Click()
    dTcheck
    End Sub

    Private Sub dTcheck()
    If date$ > "01-01-2004" Then
    Exit Sub
    Else: neworder2
    End If
    End Sub
    ----------------------------------------------------------------------------------
    the problem is that even when the date is less than 01-01-04 it still runs the [then], i have tried setting the system date to before 01-01-04 and after but regardless of this it still just runs the [then].
    very strange! any ideas or comments?

  2. #2
    Join Date
    Feb 2003
    Location
    Auckland, NZ
    Posts
    150
    Hi

    I have had a few issues with the Date funcyion as well and never use it try the Now function instead.
    JJ Kennedy
    Double J IT Solutions
    www.doublejit.co.nz

    VB 6, VB.NET, ASP.NET, MS SQL Server, MySQL, MS Access

  3. #3
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    Prove this.

    Private Sub neworder2()
    [click event for NEWORDER carries on here]
    End Sub

    Private Sub Frm_switch_new_orders_NEWORDER_Click()
    dTcheck
    End Sub

    Private Sub dTcheck()
    If date > #01-01-2004# Then <------------
    Exit Sub
    Else: neworder2
    End If
    End Sub
    Last edited by Norberto; 09-07-03 at 18:06.
    Saludos
    Norberto

  4. #4
    Join Date
    Sep 2003
    Posts
    7

    Re: silly problem with the Date$ function

    you should not use "" for string but #01-02-2003# for date format

  5. #5
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Lightbulb TIP when using dates

    When you use dates in what ever format

    Use this : YYYY MM DD

    this way u can query all over the world

    And with dates in SQL allways use the Number sign

    SO : #2003-01-02#
    will allways return all data from : January second 2003

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    might as well throw in my two cents.

    strings are strings and dates are numbers

    "02-02-1950" > "01-01-2004"
    just as
    "DAA" > "AZZZZZZZZZZZZ"
    ...which was the cause of the problem in the original question.

    dates are stored as doubles with the left-of-decimal representing days since mr gates' birthday (or is it some other globally significant event?) and the right-of-decimal representing fractional days.

    you can abuse dates as much as you like as long as you treat them as the numbers they are
    e.g.
    DaysBetweenDates = ThisDate - ThatDate
    TotalDaysInTwoPeriods = stop1date - start1date + stop2date - start2date

    izy

  7. #7
    Join Date
    Aug 2003
    Location
    SW Ohio
    Posts
    198

    Re: silly problem with the Date$ function

    Originally posted by twistedscrew


    Private Sub dTcheck()
    If date$ > "01-01-2004" Then
    Exit Sub
    Else: neworder2
    End If
    End Sub
    ----------------------------------------------------------------------------------

    any ideas or comments?
    My comment would be to do it as
    If DateValue(Date) > DateValue(Format("01/01/2004","MM/DD/YYYY")) Then
    That way you have no question that you are comparing apples to apples. I think the Date is returning a variant as opposed to a string. By doing a datevalue on both sides you are returning apples not an apple and an orange.
    Jim P.

    Supoorting Oracle, MSSQL7, Sybase 8, & Pervasive. Confusion Reigns

  8. #8
    Join Date
    Sep 2003
    Location
    Penang, Malaysia
    Posts
    9
    I have problem inserting a datetime data into a MS Access table. How do you insert a datetime value? mm/dd/yyyy hh:mm:ss AM/PM?

  9. #9
    Join Date
    Aug 2003
    Location
    SW Ohio
    Posts
    198
    Originally posted by yinsw
    I have problem inserting a datetime data into a MS Access table. How do you insert a datetime value? mm/dd/yyyy hh:mm:ss AM/PM?
    First thing - make sure the format on the field is set to mm/dd/yyyy hh:nn:ss am/pm. (Note the nn for minutes.)

    Then if you are just simply using the Now() function, Access will understand and stick it in correctly. If you are entering another date and time then you need to get the format to look like #08/23/2003 10:45:15 am# in the insert statement.

    Sometimes it is easier to handle date and time as two separate fields. It depends on your input and reporting requirements. With one field of date and time you need to always need to have DateValue(FieldName) = DateValue(#CompareDate#) instead of just comparing dates in the query.

    Sorry for the delay in answering, I've been off a couple days.
    Jim P.

    Supoorting Oracle, MSSQL7, Sybase 8, & Pervasive. Confusion Reigns

Posting Permissions

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