PDA

View Full Version : Compare datetime field with todays datetime


terp_in_umcp
05-04-2007, 06:08 PM
Hey...How do I compare a datetime field in the database with todays datetime...

Is it:

if rs("fieldname")<>getdate() then
....
else
(gotto set a cookie here)
end if

Somebody suggested I use cdate...what is tht for..is it to make sure they are both in the same format or something..if so how do I use it?

Thanks!

Fumigator
05-04-2007, 08:06 PM
If you are talking about inside a query (which I assume you are, since you posted this in the MySQL forum), then use now().


SELECT whatever
FROM wherever
WHERE datetime_field = now()

terp_in_umcp
05-04-2007, 08:15 PM
Thanks Fumi...so it should be...

if rs("Fieldname")=now() then
else
endif

guelphdad
05-04-2007, 08:34 PM
well it is unlikely that your comparison will ever be true.

Unless you run your query at the exact second that one of your values match in the database.

If you run your query at exactly 2:34:08 p.m. this afternoon then your table better have a record down to that exact second to match. or are you only looking for a partial match?

terp_in_umcp
05-04-2007, 09:36 PM
Well heres what I am trying to do....

I am trying to run a script every second in the background...tht script will check in the db to see if there's a column(Reminder) set for now...if so it will pop an alert...

I was trying to use Ajax for this and got so far...offcourse its no working:(

ON PAGE 1

<body onLoad="Something()">

-------------------------------------------------------
<script language="JavaScript" type="text/javascript">
<!--

function Something() {
var y = window.setInterval("ReminderAlert();", 2000);

}
//-->
</script>

-------------------------------------------------------

<script>

function ReminderAlert()
{

//alert("test");
ajaxpage(Page2.asp?ReturnData=SomethingNEW', 'HIDELATER');


}
</script>

----------------------------------------------------------------------
ON PAGE 2

<%if request("ReturnData")="SomethingNEW" then
mysql="SELECT * FROM Table1 where Field1='"&Users("LoginID")&"'"
Set AllRecords= Con.Execute( mySQL )

do while AllRecords.eof<>true

if cdate(AllRecords("FollowupDate"))>now() then

(Dont know what goes here)
else

end if

AllRecords.movenext
loop

%>

Somehow I dont know how I can set some kind of variable in Page2 and pass it on to Page 1 which will do the alert...

Any Ideas?
Thanks!