Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with unix timestamps deciding whether week has passed

Status
Not open for further replies.

jgd12345

Technical User
Apr 22, 2003
124
GB
Hi, I need to create a script that calculates lottery numbers. I have done this but the hard part is when the draw is done. Say I have the following variables:

$lastdraw - unix timestamp for the last draw date
$day - the day of the draw (ie 1= Monday, 2 = Tuesday...)
$hour - the hour of the draw (ie 20 = 20:00)

Each time a a draw is made the unix timestamp is recorded in the database and then put in the variable $lastdraw to help work out whether the draw should be done.

What I need to decide is whether the day and hour has come and whether it has been a week after the last draw.

I have no idea at all how I can do this and it's been rattling my brain for some time.

I hope I have made this clear and look forward to hearing your advice. Thanks
 
Unless I misunderstand, it seems that at the time you've just recorded another draw, you will certainly not need to perform another one.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yeah I recorded the last draw date because I thought it would help in calculating whether to proceed with the new draw a week from the last draw. Otherwise there's no way of determining when the last draw was made.
 
It seems to me that you shouldn't right after recording a draw make a decision whether a week has passed.

It seems to me that your script should decide at the beginning of the run whether to make that calculation.

As to how to do it, your script will, of course, fetch the last-recorded draw. Then add 60*60*24*7 seconds to that number and compare it to the seconds tick returned by PHP's time() function. If the first number is larger than the second, 7 days have passed.

You can get the hour of the day from the last-drawn lottery number set and the hour of the current day using getdate(). Then compare hours of the day to see whether the time of day is right.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ah sounds great thanks. One problem if the previous draw date is stored when the draw is run but there is a slight delay in this script being run then surely due to it using this and checking that 7 days have passed will eventually mess up as the draw will keep getting later and later until eventually the hour is not right so it'll have to wait til 2 weeks to the next draw. Sorry about the lack of punctuation in the sentence.
 
If anyone's interested this is how I'm going todo it. Using the getdate function you recommended I will store the current:

$set['dom'] - day of month
$set['month'] - month
$set['year'] - year

in the settings each time I draw is made. I also have the following in the settings:

$set['hour'] - hour of day draw tobe made
$set['day'] - day of week draw tobe made

I will also generate the variables:

$hour - hour of day (0..23)
$day - day of week (ie 0..6)
$dom - current day of month
$month - month
$year - year

Then I will use the following to decide on whether todo the draw:

if($set['year'] < $year || $set['month'] < $set['month'] || $set['dom'] < $dom) {
if($set['day'] == $day && $set['hour'] == $hour) {
// Do draw
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top