| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

01-27-04, 07:02
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 11
|
|
|
select from MyTable where date=?????
|
|
I am having a huge problem with a select-statement. I am using an access 2002database and I am trying to get a query togeather from an asp-page that selects all records from a table where the date is today. I can't figure out how to solve it.
ex. SELECT * FROM myTable WHERE columnDate = 'todays date'
how do I do it? If anyone could help me I would soooo happy 
|
|

01-27-04, 07:13
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
success will depend on what the datatype of columnDate is, and what sorts of values have been entered into it -- dates where the time component is zero, which you get from the date() function, or dates with a non-zero time component, which you get from the now() function
Code:
...
where columnDate = date()
or
Code:
...
where columnDate >= date()
and columnDate < dateadd("d",1,date())
|
|

01-27-04, 07:39
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 11
|
|
|
|
Thanx allot for that superfast answer, it was exactly what I needed. I really can't thank u enough.
|
|

02-03-04, 03:59
|
|
Guru
|
|
Join Date: Jun 2003
Location: USA
Posts: 1,032
|
|
Example setting a date range based on posted fields:
strSQL = "SELECT * FROM MyTable WHERE (TheDateField >= #" & Request.Form("MinDate") & "#) AND (TheDateField <= #" & Request.Form("MaxDate") & "#)"
|
|

02-03-04, 06:28
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
paul, the upper end of that range will not include any datetimes from the max date if the column contains datetime values with time components
you would have to either append 23:59:59 to maxdate or add 1 day to it and change <= to <
|
|

02-03-04, 07:44
|
|
Guru
|
|
Join Date: Jun 2003
Location: USA
Posts: 1,032
|
|
Quote:
|
paul, the upper end of that range will not include any datetimes from the max date if the column contains datetime values with time components
|
True, but I like date/time fields "where the time component is zero."
And for times I like to use date/time fields where the date component is zero.
|
Last edited by Bullschmidt; 02-03-04 at 07:46.
|

02-03-04, 08:26
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
no, don't tell me, let me guess...
for applications where both date and time components are required (e.g. dental appointments), you use two datetime fields, one for the date with no time component, and one for the time with no date component, right? just so the sql is easier?

|
|

02-03-04, 08:31
|
|
Guru
|
|
Join Date: Jun 2003
Location: USA
Posts: 1,032
|
|
Quote:
|
no, don't tell me, let me guess...
|
Correct, so that everything is more compartmentalized (including validating for proper date entry and in a separate field validating for proper time entry), and along with that the SQL is indeed easier.
I would generally never force a user to enter a date AND a time all in the same field.
|
Last edited by Bullschmidt; 02-03-04 at 08:38.
|

02-03-04, 08:37
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
well, no offence, but that's ugly
how do you find the number of elapsed hours between two datetimes? if they can be separated by one or more days?
in sql server, i would use
select datediff(h,datetime2,datetime1)
|
|

02-03-04, 08:50
|
|
Guru
|
|
Join Date: Jun 2003
Location: USA
Posts: 1,032
|
|
Don't know that I ever put the difference in hours directly in a SQL statement (as opposed to perhaps calcuating in VBScript after the recordset has already been created), but if this works in a SQL statement:
SELECT DateDiff('h', datetime2, datetime1)
Then I would assume that perhaps this would work too:
SELECT DateDiff('h', date2 + time2, date1 + time1)
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|