[RESOLVED] Working with dates... How to check if a certain date is between a certain period?
I'm trying to find a VB code that checks if my date on a label is between a certain dateperiond that is chosen from two DateTimePickers...
I'm trying something like:
Code:
Dim MyDate as Datetime = Convert.ToDateTime(LabelDate.Text)
If MyDate <> between DateTimePicker1.Value and DateTimePicker2.Value Then
.......
End If
(I tried to do this with a query, but I'm using SQL Server Compact, and it does not allow me to do:
... WHERE NOT @MyDate BETWEEN @Val1 AND @Val2
Re: Working with dates... How to check if a certain date is between a certain period?
See if this works:
Code:
If MyDate > DateTimePicker1.Value and MyDate < DateTimePicker2.Value Then
I haven't tested this code.
:wave:
Re: Working with dates... How to check if a certain date is between a certain period?
You should be able to do the same thing in SQL
WHERE @MyDate < @Val1 OR @MyDate > @Val2
(Also have not tested it, but no reason why it should not work!)
Re: Working with dates... How to check if a certain date is between a certain period?
Quote:
Originally Posted by
akhileshbc
See if this works:
Code:
If MyDate > DateTimePicker1.Value and MyDate < DateTimePicker2.Value Then
I haven't tested this code.
:wave:
Yep, this worked... Can't understand why I didn't think of this before... :D
Quote:
Originally Posted by
Grimfort
You should be able to do the same thing in SQL
WHERE @MyDate < @Val1 OR @MyDate > @Val2
(Also have not tested it, but no reason why it should not work!)
I did try tis before, but it gives me the same error as it did when I wrote the code seen in the first post...
"No mapping exists from DbType AnsiString to a known SQL Server Compact data type."
Re: [RESOLVED] Working with dates... How to check if a certain date is between a cert
Ahh but you didn't mention that in your first post :). You are passing your dates through as string instead of dates then, or something asimilar.
Re: [RESOLVED] Working with dates... How to check if a certain date is between a cert
Quote:
Originally Posted by
Grimfort
Ahh but you didn't mention that in your first post :). You are passing your dates through as string instead of dates then, or something asimilar.
No. The dates are passed as dates.
The reason for this error is still unclear to me, but it seems to be with the SQL Server Compact.
When I use the identical query with SQL Server, it works perfectly. But now I had to switch to SQL Server Compact because of easier installation, the same query no longer works...
Don't know why, but I managed to do the thing another way. :)
Re: [RESOLVED] Working with dates... How to check if a certain date is between a cert
I think, stored procedures doesn't work in Compact edition : comparison of Compact edition and Express edition
:wave: