|
-
Mar 22nd, 2011, 04:53 AM
#1
Thread Starter
Lively Member
[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
-
Mar 22nd, 2011, 05:01 AM
#2
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.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 22nd, 2011, 05:12 AM
#3
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!)
Last edited by Grimfort; Mar 22nd, 2011 at 05:13 AM.
Reason: Changed it around to check the not
-
Mar 22nd, 2011, 06:16 AM
#4
Thread Starter
Lively Member
Re: Working with dates... How to check if a certain date is between a certain period?
 Originally Posted by akhileshbc
See if this works:
Code:
If MyDate > DateTimePicker1.Value and MyDate < DateTimePicker2.Value Then
I haven't tested this code.

Yep, this worked... Can't understand why I didn't think of this before... 
 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."
-
Mar 22nd, 2011, 06:35 AM
#5
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.
-
Mar 22nd, 2011, 07:53 AM
#6
Thread Starter
Lively Member
Re: [RESOLVED] Working with dates... How to check if a certain date is between a cert
 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.
-
Mar 22nd, 2011, 07:59 AM
#7
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
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|