PDA

View Full Version : Php (mysql) Date Calculations??


timsim00
4-9-03, 06:34 PM
Hello all...

I am building a new site, I have php authentication down, but what I want to do is have a timer function that denies logins from a certain time of the week to a certain time of the week.

Like for instance. I have a sight where everyone logs in to make their lottery picks (example), and on Wednesday morning I want to be able to automatically turn off the login process by using a date/time qualifier.

then open the login process again the following day.

Any ideas?

Thanks,

Tim
timsim00@tsimpson.com

netaustin
4-10-03, 06:30 AM
Read the php.net information on time(), mktime(), and date().

I'm sure that you can find what you need there - php time functions are so powerful that they can be a little confusing.

If you'd like specific help, drop me an email or PM me and I'd be happy to crunch some code for you.

Storms
4-10-03, 09:46 AM
I'm looking for a time function to .... and hope that perhaps in educational purpose we can build and discuss the time functions here? It is so nice learning from others instead of grabbing codes and modify them without really knowing what you do.... It is especially educational to learn the "up-buildning process"...

I'm tryiing to put together a code that does this:

1) Count down from a particular time of the day
2) Excludes counting in different days
3) Prints different msg depending on the results from p.t 1 and 2

The countdown isn't that big a problem as you can use for instance:

// for day, month and year... would look like this 040403
$today = date( "dmy" );

or

$today = getdate( [mday,mon,year]);

or

$today = getdate();
$month = $today['month'];
$mday = $today['mday'];
$year = $today['year'];

// print the result
echo "$month $mday, $year";

-----------------


to count down you use the date - you wish

eg.

// Define your date for open or closed
$yourdate = "110403";

// Get todays date
$today = date( "dmy" );


// Checking to see if the date is correct
If($yourdate == $today){
echo"(subscriptions open)";
} else {
echo"(subscriptions closed)";
}


There are some small issues though

1) you'll need to convert to your time sone.... do a define
2) The "$yourdate" needs to be converted into weekdays... so that you test for days instead...

e.g

$closeday = "3"; // which is wednesday or so....

I would love to work further with you guys on this if you would like so.. .I could make a functional code for your fitting your request, but know there are many very skilled people here, e.g Halfabee, and that we could learn a great deal from them....

Anyone up for this? Find a base we can start from and the build out? And if so, please do some explaning to the codes as this helps us novices to understand the syntax...

devinemke
4-10-03, 10:19 AM
Like for instance. I have a sight where everyone logs in to make their lottery picks (example), and on Wednesday morning I want to be able to automatically turn off the login process by using a date/time qualifier.
if you want to prevent people from logging in at any time on a Wednesday:

if (date ('D') != 'Wed') {...display login code...}
else {echo 'Sorry, we are closed on Wednesdays.';}

Be advised that the above code will be relative to US PST time (powweb is located in California). If you want it relative to another timezone then you will have to offset the current timestamp to your timezone.

Storms
4-10-03, 10:43 AM
didn't I tell you these guys know the deal:)

It is so refreshing to see you guys in action....

Devinemke

Can you please get more into the timestamp func and how to convert this to your zone... and are you up for any ideas for a countdown as described above?

devinemke
4-10-03, 10:54 AM
You need to add/subtract the number of seconds to/from Pacific Coast time. For example, I live in New York City, Eastern Time. The difference is 3 hours ahead (10800 seconds).

if (date ('D', time () + 10800) != 'Wed') {...display login code...}
else {echo 'Sorry, we are closed on Wednesdays.';}

timsim00
4-10-03, 11:31 AM
Thanks much devinemke, I think that code will work just fine. I am on the Pac. Coast, so all is well there.

I may to block the login for several days, from like a thursday through sunday, or just sunday sometimes. Depends. I will probably do a lot of "else if's". Or pull the days that I dynamically enter from an array. Not sure yet.

But thank you again...I don't know my date functions quite that well. It seems everytime I try and learn something about date/time functions, I get more confused!

T