Populate a query form with current date (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


Guest -> Populate a query form with current date (3/12/2001 23:06:00)

I currently query a scheduling database using drop down boxes for month/date/year to return date specific results. Any ideas on how I could use the current date as the first query when the asp page is opened and then use the drop down boxes to search other dates? I have a javascript date displayed as a courtesy to the user but it would be wonderful to have the page open to the current date and its attendant schedule then allow the user to search other dates.
Thanks,
Mike




Vince from Spain -> RE: Populate a query form with current date (3/12/2001 18:28:00)

I take it your query page is an Active Server Page (.asp) ? You have the Date() function which will return the current date, and you can use this in your SQL query like . . .
sql = "SELECT * FROM results WHERE mydatefield=#" & Date() & "#;"

for instance . . .

Hope this helps

Vince

------------------
Internet Business Solutions S.L.(Spain)





Guest -> RE: Populate a query form with current date (3/13/2001 20:11:00)

Thanks Vince.
Yes it's an ASP page. Three of the database columns are Month, Day, Year in the format March 12 2001. I am also saving the date() as a seperate column.
if I use sql=SELECT*FROM table WHERE (date='#" & Date() &"#' AND Doctor = '%%name%%' AND Month='%%month%%' AND day='%%day%%' AND year='%%year%%') and use a form query to call the month, date and year in three drop down menu boxes the three drop down menu boxes are replaced with a text query box with the value #date# in it. When I remove the sql reference to the date then the page works fine again. I understand how to query using the Date() all by itself and how to use the drop down boxes all by themselves. Am I asking too much for a sql stmt that will do both on the same page?




Vince from Spain -> RE: Populate a query form with current date (3/13/2001 20:19:00)

Hi Mike,
I must admit to being just a little bit confused about what you want to do with this. Maybe a URL would help. Anyway, here are a couple of points that might help.
You have Day(), Year() and Month() functions available in ASP, like for instance . . .
Response.Write Month(Date()) & " " & Day(Date()) & " " & Year(Date())

If I want to have an action on an asp page that only happens the first time a page is called, and not when it calls itself again, I normally use a "hidden" variable in the page form. For instance . . .
<input type="hidden" name="calleditself" value="1">

So now I can check in the page . . .

<%
if Request.Form("calleditself") = "1" then
.....do something
else
.....do something else
end if
%>

All the best

Vince





Guest -> RE: Populate a query form with current date (3/15/2001 20:18:00)

Vince your beautiful!
That's exactly what I needed to solve the problem.
Thank you!!
Mike




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
6.201172E-02