PDA

View Full Version : Using the date command


Switch17
12-25-2002, 12:06 AM
I'm still a young lad at learning php, so I could use some advice. I run a fantasy fooball site, that each week, I go into my mysql database and change the week to the latest week in the season. What I'm hoping to do is to be able have php look at the current date on the individual's pc, and based on that date, it will select the correct week. I don't think is to complex, but again, i'm a newbit at php. Any ideas.

Thanks
Switch

raf
12-27-2002, 09:24 AM
Ideas, yes, but mainly questions.
Why do you store that date in the datebase ? Why do you want to use the clients date ? What exactly are you trying to do ?

I'd use the date from the server (since the clients date could be wrong) and just use that as a criterium in my sql-statement (to update the db, or as a condition in my select-statement)

duniyadnd
12-27-2002, 10:05 AM
not exactly helping you here, but to add on to what raf said, it creates consistency, also, what happens if someone is in a different timezone, and possibly on another date? that could create some confusion for sunday/monday nights to show the correct week.

just a thought
duniyadnd

Switch17
12-27-2002, 07:23 PM
Sorry for the confusion. Let me try and clarify a bit. What I do now is simply add a new row to my database. It simply works as follows:

season week
2002 1
2002 2
2002 3

and so on. So each week, I just add the next week of the season. I then run a query that gets the lastest week in the database which lets my team owners to view that latest week, and all prior weeks. I plan to try and automate this for next year instead of adding the new week number each week by looking at when the NFL season starts, and then based on that date setting and an individuals pc date, it would find the right week, and give the current and prior weeks. I'm starting to figure this out. I believe its just a matter of a combination of the getdate and if commands.

duniyadnd
12-27-2002, 11:26 PM
To get the week number of the year, you can compare it to the following script:

date(W);

Make sure the W is capital, otherwise you'll get only the day of the week. Only downside in this respect is you create your weeks from the week you're actually starting from (ie. if you start this week, you label it week 52) and it doesn't check the year, so you'll start from 1 in the first week of January.

Duniyadnd

Switch17
01-05-2003, 09:33 PM
duniyadnd. Thanks for your help. What I'm trying do is a little different. I'm trying to set this up so it will first look at the end users date on their PC, and then based on that date, it will give them the correct weeks information. So that if a users PC is January 5, 2003, or whatever, it will give them week 1 or whatever week is necessary. But I need this to be the user's PC, and not the date that is on my hosts web server. So I want it look at the endusers date, and then based on that date give me the correct week I want.

I was hoping that getdate would give me the users date, but it gives me my hosts date instead. I'll gonna keep plugging away reading and learning, but if you guys can offer any advice, I'd be much appreciated.

Switch

mordred
01-05-2003, 11:45 PM
You are stuck in a dead end street. PHP runs on the server, so it's just not possible to query the client's computer date. That's not only a limitation of PHP, but of all server-side languages. It's not possible to know the time settings of any client, that's due to the client-server architecture this whole thing relies upon. You could do it however get the user's date with javascript and ask the client to submit that value to compare against on server side.

HTH

Richard
01-06-2003, 12:27 AM
Why exactly do you want to get the client's date ? What's wrong with the server one ?