Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use only date portion to compare SQL datetime v
Message
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01059167
Message ID:
01059350
Views:
10
Juan, you need to be careful that no records will ever exist between 11:59 and midnight.

A better option is to strip the time portion of by converting it to a char(10) field then back to a datetime.
SELECT *
   FROM transactions
   WHERE CONVERT(datetime,CONVERT(char(10),dTrnDate,101)) = @dIniDate
Kurt

<
>Thank you Cetin,
>
>We are doing something similar directly on SQL Server:
>
>select *  from Transactions
>where dTrnDate >= @dIniDate
>and dTrnDate <= @dFinDate+0.9999
>order by dTrnDate
>
>
>
>This expression: @dFinDate+0.9999 produces a date like:
>'09/01/2005 11:59PM'
>
>
>Thanks
>
>
>
>
>>>Hello
>>>
>>>A datetime field in SQL may be 'Oct 1,2005 04:00PM'
>>>
>>>But when selecting records for a range of dates from 'Oct 1,2005' to 'Oct 1,2005' , SQL Server assumes a default time of '12:00AM' so the transaction is not selected.
>>>
>>>A solution is to set the final search date to 'Oct 1,2005 11:59PM' but my question is : Is it possible to compare only the date portion and ignore the time portion ?
>>>
>>>Thanks
>>
>>It'd take more to ignore time portion IMHO. Adjusting enddate is easier I think. ie:
>>
>>dStart = {^2005/10/05}
>>dEnd   = Dtot({^2005/10/05}+1)-1
>>SQLExec(m.lnHandle,;
>> 'select * from myTable where myDateTime between ?m.dStart and ?m.dEnd','myCursor')
>>
Cetin
Previous
Reply
Map
View

Click here to load this message in the networking platform