Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server and VB6. Problem with Getdate() 2

Status
Not open for further replies.

MarKes

Programmer
May 3, 2001
18
0
0
ES
I have a problem in SQL Server using from VB6.
My problem is in the datetime fields when I try to compare a 'Date and Time' that match with the value of the field.

When I save a Date field with the Getdate() function of SQL SERVER and later I try to compare this field with another date, using the Getdate() function of VB6, the query doesn´t find anything, however if I write the field by hand, and exactly equal that this is with the Getdate(), the query find it...

There is any way to Compare the 'date' and the 'time' together or I have to use the function convert to compare the 'date' part of the field only, and then use another time the function convert to compare the 'time' part of the field?.

Aren´t the Gettime() of VB6 and SQL equals?
where is the different?

I don´t know if you understand me. My english is very bad...
I´m spanish.

Thanks in advance

 
The problem is that SQL Servers datetime datatype holds a date/time value to one three-hundredth second. So testing for equality is almost impossible here.

You would need to convert that data to more standard dd/mm/yyyy format to do a straightforward comparison.

Also for this type of date field I tend to use smalldatetime. I find it more than adequate in general, since I rarely need to hold date values to such a degree of accuracy. smalldatetime holds a date/time value accurate to the minute. Perhaps this would be better for you.

Hope this helps (and your English is great)
 
Conversion for SQL would be:
select convert(varchar,getdate(),101)

and for VB6:
Format(Now(), "mm/dd/yyyy")

these 2 should compare ok.
 
Note also that SQL Server and VB use a different base for their dates. Internally, a date/time is held as a floating point number with the date as the integer part and the time as the decimal. There is a one day difference between these two (MicroSoft) applications!. I forget which is which, but one has day zero as 31 December 1899 and the other as 1 January 1900! The other thing to watch is that both apps are set to the same date format (British / American, etc). I prefer to hold date-times as numerics so as to avoid localisation issues but then have to watch out for point one above!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top