how does one search using date "from to" while still selecting a user from a drop down list
how to search using php and sql server as database
Collapse
X
-
Hey.
You should be able to just do something like:
[code=sql]SELECT [stuff]
FROM [tablename]
WHERE [datefield]
BETWEEN '2010-01-01' AND '2010-02-01';[/code]
I'm no expert on Microsoft SQL Server in particular, but the basic syntax is the same for most types of SQL based databases.
If that is not what you are looking for, please elaborate on your question. Perhaps show us a sample of the code you are having trouble with. -
In addition SQL Server does not have a DATE data type, only DATETIME so to capture a complete two days you will needCode:SELECT [stuff] FROM [tablename] WHERE [datefield] BETWEEN '2010-01-01 00:00:00.000' AND '2010-02-01 23.59.59.999';
Comment
-
Comment
-
Sorry, yes two months.
Dates are a pain. Have to use CAST or CONVERT to strip off time segment.
Need to be careful with comparisons, which is why I rather rudely interupted, AtliComment
-
this is the sample code
Code:$vUserActQuery = ' SELECT ds_description,ua_busscompid, ua_type, ua_actionid , ua_startdate, ua_enddate, user_comments FROM dms_useraction,status WHERE ua_userid = \''.$vUserId.'\' AND ua_actionid=ds_id' from this part its wrong help me out AND ua_startdate >= \''.$vStartDate.'\' AND ua_startdate <= \''.$vToDate.'\';
Comment
-
I prefer to wrap queries in double quotes.
It looks cleaner than escaping, so makes spotting errors easierCode:$vUserActQuery = "SELECT ds_description, ua_busscompid, ua_type, ua_actionid , ua_startdate, ua_enddate, user_comments FROM dms_useraction,status WHERE ua_userid = $vUserId AND ua_actionid = ds_id from this part its wrong help me out AND ua_startdate >= $vStartDate AND ua_startdate <= $vToDate;
I used to make that error.Code:AND ua_startdate >= '$vStartDate' AND ua_startdate <= '$vToDate'
Code:AND ua_startdate BETWEEN '$vStartDate' AND '$vToDate'
DON'T overlook the time element as in my first post.
And may I suggest studying the JOIN commandComment
Comment