|
-
Mar 19th, 2004, 08:50 AM
#1
Thread Starter
New Member
sql statement select range 2 date field in sql server
1. how do i write a sql statement to select 2 range date fields in sql server
i tried in usual vb6 code but its not working
vb.net & sql server
=============
field name = datein, dateout
so it will be datein => txtdatein.text and dateout =< txtdateout.text
my date format is "dd/MM/yyyy"
2. if i use this below method, the sql server reads the date format as "MM/dd/yyyy" but in my database date stored as "dd/MM/yyyy". how do i get the format to read field in db as "dd/MM/yyyy".
Where DateIn >= '" & txtDateIn.Text & "' and DateOut <= '" & txtdateOut.Text & "' "
thanks guys.
-
Mar 19th, 2004, 09:36 AM
#2
you can use the between method for 2 dates like that. From an SQL statment, I think you're forced to use the really wierd SQL Server format, however if you can use stored procedures, you can do that on by calling the DATEFORMAT method...
Code:
CREATE PROCEDURE spMyStoredProcName
@DateIn (fieldtype),
@DateOut (fieldtype)
AS
SET DATEFORMAT dmy
SELECT * FROM mytable
WHERE datein BETWEEN @DateIn AND @DateOut
-
Mar 19th, 2004, 11:25 AM
#3
Frenzied Member
This is how I do mine
VB Code:
CREATE PROCEDURE stp_GetMailingByDateRange
@StartDate varchar(10),
@EndDate varchar(10)
AS
SELECT A.ESPEmail_MailingID,
A.SubjectLine,
A.MailingDesc,
A.EmailCreator
FROM dbo.ESPEmail_Mailing As A
[color=red]WHERE A.MailingDate >= @StartDate AND A.MailingDate <= @EndDate[/color]
AND A.InActive = 0
AND A.EmailSent = 0
ORDER BY A.SubjectLine, A.MailingDesc
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Mar 19th, 2004, 11:46 AM
#4
Lively Member
The Date format needs to be : 'DD/MMM/yy'
this then tells the sql server which part is the month
then just convert it back when you get the info
by Format(Date,"dd/MM/yy")
you also need to dim dates as show below
so it should look like this:
Dim DateIn as Date
Dim DateOut as Date
DateIn = Format(txtBox.Text,"dd/MMM/yy")
DateOut = Format(txtBox2.Text,"dd/MMM/yy")
then put the DateIn and DateOut into the query this should slove it.
Last edited by nokia8210; Mar 19th, 2004 at 11:49 AM.
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
|