|
-
Feb 22nd, 2007, 08:23 AM
#1
Thread Starter
Hyperactive Member
Need help with using TimeStamps from Database
I am building an application that runs once every two hours during the day. Its purpose is to check a database to see if there have been any orders placed in the last two hours (since the last time it was run). The Ordering system adds a timestamp to the table so I am thinking that is the best way to track orders.
My first thought was to have my program look at the current time then subtract two hours from it and pull the orders that way. The problem with that is that if for some reason the program doesn't run at the time it should I may miss an order or two.
So I think I am going to have to do is store the last timestamp somewhere and then look for orders based on the Current Time minus the last timestamp. Does that sound right? If so I think the best way to accomplish that would be to store the timestamp in an XML file for quick reference. Any other ideas, thoughts or suggestions?
-
Feb 22nd, 2007, 09:04 AM
#2
Re: Need help with using TimeStamps from Database
That sounds like the best idea. Just save the date you last requested orders, and only ask for new orders since that date. That means if you miss one slot, the next one will pick up 4 hours, not just 2. No need to do any date calculations at all.
ie
savedate = nothing 'first run
get orders since forever
save date to xml
...
2 hours later
load date from xml
get orders since this date
save current date to xml
etc etc
-
Feb 22nd, 2007, 09:56 AM
#3
Re: Need help with using TimeStamps from Database
Other idea is if this table you are looking at contains a unique incrimental field like an order number...you could just store that last order number processed then the next time your program runs it will only look at order numbers that are greater than the last 1 processed.
-
Feb 22nd, 2007, 09:59 AM
#4
Re: Need help with using TimeStamps from Database
That would be a better solution, as you dont have to worry about your PC being out of date in comparison with the database, or if you run it from two or more computers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|