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
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 & "#"
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)
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
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.
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.