Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Posts
    1

    Unanswered: subtracting two Dates

    I have a select statement in some Java code to access a Access table.

    Each row in the table has a date timestamp.

    I would like to fetch rows that are:

    today - 1 month

    or

    today - 2 months.


    My select statement looks something like this...


    StringBuffer Itemsql =
    new StringBuffer( "SELECT ID, " +
    " NAME, " +
    " UPC, " +
    " PRICE " +
    "FROM Item " +
    "WHERE DateUsed > ( #Today# - #" + DateSince + "# ) ");


    It's my understanding that dates must be preceded with a #, but I'm
    getting a syntax error when I execute it.

    Thanks....

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Try to use the DATEADD function something like that

    DateAdd("m", -1, yourDate)
    ' this will give you a date less than yourDate with one month


    DateAdd("m", -2, yourDate)
    ' this will give you a date less than yourDate with two month

Posting Permissions

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