Solved

Time/Date Query

Posted on 2016-09-26
11
45 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

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 informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 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