Solved

Time/Date Query

Posted on 2016-09-26
11
47 Views
Last Modified: 2016-09-27
Hi there, I am not sure if this is correct or not...

Set CheckCurrency=oConn.Execute("SELECT * FROM site_curr WHERE curr_update=<#"&Now()&"# AND curr_uptime=<#"&Time()+1&"#")

Open in new window


What I want to do is check if these values is more than 1 hour old from the values in the DB

eg if it is 10am, are the values prior to 9am (that same day)

Any help is appreciated
0
Comment
Question by:Graeme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 100 total points
ID: 41816486
try:

Set CheckCurrency=oConn.Execute("SELECT * FROM site_curr WHERE curr_update=<#"&Now()&"# AND curr_uptime=<#DateAdd( "h", "Now()" 1 )#")
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41817145
what's your database? Access?
0
 

Author Comment

by:Graeme
ID: 41817250
Hi Ryan, yes Access 2003

BigMonty, trying your code, got this error:
Expected ')'

/home.asp, line 112

Set CheckCurrency=oConn.Execute("SELECT * FROM site_curr WHERE curr_update=<#"&Now()&"# AND curr_uptime=<#DateAdd( "h", "Now()" 1 )#")

Open in new window

Points to the h in DateAdd
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 52

Assisted Solution

by:Ryan Chong
Ryan Chong earned 400 total points
ID: 41817308
in access you can try use DateDiff function to get the datetime difference:

DateDiff Function
https://support.office.com/en-us/article/DateDiff-Function-e6dd7ee6-3d01-4531-905c-e24fc238f85f

to get records which are more than 1 hour old from the values in the DB, you can try:
....
Where DateDiff ( 'n', curr_update, now)  >60

Open in new window

hence:
Set CheckCurrency=oConn.Execute("SELECT * FROM site_curr WHERE DateDiff ( 'n', curr_update, now)  >60")

Open in new window

if got record(s) returned, it means got record(s) is more than 1 hour old.
0
 

Author Comment

by:Graeme
ID: 41817314
Looks very promising

And from here, I would use this IF statement to execute if it is outside 60min old?

If Not CheckCurrency.EOF Then

Open in new window

?
0
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 400 total points
ID: 41817318
And from here, I would use this IF statement to execute if it is outside 60min old?
yup, like:
Set CheckCurrency=oConn.Execute("SELECT * FROM site_curr WHERE DateDiff ( 'n', curr_update, now)  >60")

If Not CheckCurrency.EOF Then
    response.write "at least 1 hour old record was found"
else
    response.write "no 1 hour old record was found"
end if

Open in new window

you can also do a Count in your SQL statement if necessary or adding Top 1 into your Select statement above if you just want to check the existence of record.
0
 

Author Comment

by:Graeme
ID: 41817329
Cheers for that, work great! (by itself)

In reference to one of our previous questions (aspJSON), when we add this query & If statement, would there be any reason why aspJSON now become an error?

It does not error when the If statement and query commented out or if aspJSON isnt within the If statement, but within it errors, cannot figure out why
Class aspJSON

Open in new window

0
 

Author Comment

by:Graeme
ID: 41817330
Change the name of the page to:

http://dev.gptouring.com.au/currAPI.asp (same user and pw)
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41817339
when we add this query & If statement, would there be any reason why aspJSON now become an error?
it shouldn't happened as both are not really "related" to each other. need to know the error message you encountered.

if it's a totally separate question, perhaps we can follow up in another new thread instead? so it's more likely to be traceable cheers.
0
 

Author Comment

by:Graeme
ID: 41817340
Yes of course, I will start another thread for it

Cheers
0
 

Author Comment

by:Graeme
ID: 41817347
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question