Results 1 to 6 of 6

Thread: need help with date function

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    19

    need help with date function

    hi guys.
    i have a code here but i dont know what is the problem.
    i have my connection in module.
    i want my exdate to show in my listview from database wherein it is less than the date now. but it doesnt show me anything.
    Code:
    RSconn "select * from tblp_inventory where Exdate < '" & Date & "' "
    With rs
    
    Do While Not rs.EOF
        Set a = Me.ListView2.ListItems.Add(, , rs.Fields!item_code)
        a.SubItems(1) = rs.Fields!Generic_Name
        a.SubItems(2) = rs.Fields!exdate
        a.SubItems(3) = rs.Fields!stock_hand
    .MoveNext
    Loop
    rs.Close
    
    End With

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: need help with date function

    What type of database are you using? You shouldn't be comparing dates as strings.
    If Exdate is a date datatype in your database, maybe the SQL statement should be
    "select * from tblp_inventory where Exdate < #" & Date & "#"
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: need help with date function

    That is potentially better (depending on the database system), but there is still at least one other problem - the formatting of the date value.

    For an explanation and examples of what you should be doing, see the article How do I use values (numbers, strings, dates) in SQL statements? from our Database Development FAQs/Tutorials (at the top of the Database Development forum)

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    19

    Re: need help with date function

    Im having trouble doing it.
    Im using sqlyog as my database.
    i used sir lavolpe code but it has an error and i think its for msaccess?

    i look at the site sir si the geek game and i cant find a way to make it run

    sorry new to vb

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    19

    Re: need help with date function

    When i use this code my program works fine..
    RSconn "Select * From tblp_inventory Where exdate < '2012/02/23'"
    it gives me the result

    But then when i change it to
    RSconn "Select * From tblp_inventory Where exdate < 'Format(date,yyyy/mm/dd)'"
    it does not work. i want to compare it with the current date.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: need help with date function

    I've never used sqlyog, but your working example (with a fixed value) shows the format you should be using... now all you need to do is pay a bit more attention to the quotes etc in the example at the end of the FAQ article.

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