Results 1 to 18 of 18

Thread: Database dates (Access and SQL Server)

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Question Database dates (Access and SQL Server)

    Ok, I have a date field in my Database, Modified_Date, which stores the date as 27/08/02 13:57:55.
    If I wanted to select anything that had been changed since I last loaded, ie anything greater than 27/08/02 13:57:55 what would my SQL SELECT statement look like?
    Code:
    SELECT *
    FROM tblTable
    WHERE Modified_Date >  This is the bit I can't work out...:(
    I really should know it, but can't quite get it to work...

    Anyone...

    Call myself a pro VB Developer...*SIGH* Bad Woka *SLAP*

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    My suggestion would be to place two textboxs on your screen (start/end date).

    Then, code a BETWEEN in your SQL query to look for records that fall between those input dates.

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    well how would you know the last date since last loaded? when you do load the data.. do you store that date/time anywhere to do the compare with?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    A SELECT MAX(datemodified) should give you the latest modification date.

    No?

  5. #5
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478

    WhoeHaHaHaHa me helping the pro

    Should i


    ok try this
    VB Code:
    1. "SELECT *
    2. FROM tblTable
    3. WHERE Modified_Date >= #" & Format(start, "dd/mm/yy hh:mm:ss") & "#"

    This is if u are sure it is stored in that format.



    [EDIT]
    You know start is a variable with a date in it
    [/EDIT]
    Last edited by swatty; Sep 20th, 2002 at 06:34 AM.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Hack
    A SELECT MAX(datemodified) should give you the latest modification date.

    No?
    thats what i was thinking... but if you then did

    select * from table where Modified_Date > "THE SELECT MAX VALUE"

    you won't get any data.. because no Modified_Date will be greater than the max you just pulled...

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    SELECT *
    FROM tblTable
    WHERE Modified_Date > '2002/08/27 13:57:55'

    If you specify the date in ISO 8601 format, both Access as SQL server should understand it. I'm not sure if Access 97 and earlier can understand the single quote, maybe you need the # sign instead.

    EDIT: This is the way if the field is a Date field. The way the date is displayed has nothing to do with the way it is stored. If you used a text field, you have a problem.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Originally posted by Kleinma
    thats what i was thinking... but if you then did

    select * from table where Modified_Date > "THE SELECT MAX VALUE"

    you won't get any data.. because no Modified_Date will be greater than the max you just pulled...
    Righto...so it seems that two queries might be the answer. The first would get the last modified date, store it into a variable, which could be used in the second query.

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Frans C
    SELECT *
    FROM tblTable
    WHERE Modified_Date > '2002/08/27 13:57:55'

    If you specify the date in ISO 8601 format, both Access as SQL server should understand it. I'm not sure if Access 97 and earlier can understand the single quote, maybe you need the # sign instead.

    EDIT: This is the way if the field is a Date field. The way the date is displayed has nothing to do with the way it is stored. If you used a text field, you have a problem.
    is this all he wanted??? man if so I think the rest of us were looking at the problem a little to hard...

    I guess woka just wanted syntax

  10. #10

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Slime on a rock makes for a great pudding...

    Arrr...but if you do a Refresh on the collection, say 10 minutes later, then there may be a modified date that is greater
    When I load my records into a collection I store the maximum Modified_Date field in a modular level varible, then when I do I refresh it only loads records that have been updated, quicker than loading the whole recordset again
    I am using the Timestamp field type in SQL, but Access doesn't have this, no my DLL will not work if I point it towards an Access database. If, instead of a timestamp field, I use a Modified_Date field then this is easily transferable to Access or SQL Server...

    Swatty - I take that as I compliment

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Slime on a rock makes for a great pudding...

    Originally posted by Wokawidget
    Arrr...but if you do a Refresh on the collection, say 10 minutes later, then there may be a modified date that is greater
    When I load my records into a collection I store the maximum Modified_Date field in a modular level varible, then when I do I refresh it only loads records that have been updated, quicker than loading the whole recordset again
    I am using the Timestamp field type in SQL, but Access doesn't have this, no my DLL will not work if I point it towards an Access database. If, instead of a timestamp field, I use a Modified_Date field then this is easily transferable to Access or SQL Server...

    Swatty - I take that as I compliment
    you also have to remember that sql likes ' around a date while access like # around a date...

  12. #12

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Circles in the sand implicate cake is on the way...

    Which is correct...?
    Code:
    WHERE Modified_Date > '2002/08/27 13:57:55'
    OR
    Code:
    WHERE Modified_Date > #2002/08/27 13:57:55#
    Woka - having a crappy day - widget

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Circles in the sand implicate cake is on the way...

    Originally posted by Wokawidget
    Which is correct...?
    Code:
    WHERE Modified_Date > '2002/08/27 13:57:55'
    OR
    Code:
    WHERE Modified_Date > #2002/08/27 13:57:55#
    Woka - having a crappy day - widget
    read my post above this one

  14. #14

  15. #15

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Tis OK though, coz I would only have to update one function in the 3rd Tier (Data Tier) of my app...
    VB Code:
    1. Public Function NormailseDate(ByVal pdteDate As Date) As String
    2. Dim strTemp   As String
    3.    strTemp = "#" & Format(pdteDate, "mm/dd/yyyy hh:nn:ss") & "#"
    4.    NormaliseDate = strTemp
    5. End Function

    Woka

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Wokawidget
    strTemp = "#" & Format(pdteDate, "mm/dd/yyyy hh:nn:ss") & "#"

    Woka

    WATCH THOSE N's!!!!!!

  17. #17

  18. #18
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478

    What a day , deffinitly having a nice we to come

    Originally posted by kleinma
    WATCH THOSE N's!!!!!!

    Could it be those were nanoseconds but don't they have to be put after the seconds ???


    Which is correct...?

    VB Code:
    1. WHERE some_text like 'Woka Woka Woka said packm%'
    OR

    VB Code:
    1. WHERE some_text like 'Woka Woka Woka said packm*'

    All depends on the db your testing against
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

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