Solved

Time/Date Query

Posted on 2016-09-26
11
33 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 32

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 49

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
 
LVL 49

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 49

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 49

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now