Time Help

Discussion forum for MOD Writers regarding MOD Development.
Locked
A.I. BOT
Registered User
Posts: 1848
Joined: Thu Apr 17, 2003 11:43 pm
Location: Newfoundland, Canada
Contact:

Time Help

Post by A.I. BOT »

Basically, for my Rivals MOD, I'm adding a feature that lets users set when a tournament is going to start.

There are a few drop down boxes. Month, Day, Year, Hour and Minute of when the tournament will start.

My problem is, when I submit the tournament and go to view when it is starting, the time is off/wrong.

Example: If I put in July 04 2009 at 4:00AM... it might show up as Nov 21 2009 at 3:00PM. Using "$user->format_date ( $tournament->data[ 'tournament_startdate' ] )"

Here is the snippit of code that convert the strings into usable timestamp.

Code: Select all

$start_date	= strtotime ( "{$tournament_startdate[ 0 ]}/{$tournament_startdate[ 1 ]}/{$tournament_startdate[ 2 ]} {$tournament_startdate[ 3 ]}:{$tournament_startdate[ 4 ]}" );
So thats MM/DD/YYYY HH:MM. $start_date then gets put into the database for "tournament_startdate"

Any idea on why the times arn't right? I know that format_date is going to fix it for the user's time but I don't see why the month should be off or the date be off, etc. Do I have to include the admin's timezone for strtotime to fix this?
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: Time Help

Post by Erik Frèrejean »

Well first of all is there a specific reason you use strtotime for this?
If not you might want to look at mktime

Code: Select all

int mktime  ([ int $hour  [, int $minute  [, int $second  [, int $month  [, int $day  [, int $year  [, int $is_dst  ]]]]]]] )
inorder to generate a timestamp from this data.
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
A.I. BOT
Registered User
Posts: 1848
Joined: Thu Apr 17, 2003 11:43 pm
Location: Newfoundland, Canada
Contact:

Re: Time Help

Post by A.I. BOT »

Ah yeah! I completely forgot about mktime *smacks head*... I'll try it out and let you know :)

Thanks!
A.I. BOT
Registered User
Posts: 1848
Joined: Thu Apr 17, 2003 11:43 pm
Location: Newfoundland, Canada
Contact:

Re: Time Help

Post by A.I. BOT »

Ah that did the trick, thanks !
Locked

Return to “[3.0.x] MOD Writers Discussion”