Solved

Time/Date Query

Posted on 2016-09-26
11
42 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
  • 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 50

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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 50

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 50

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 50

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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