TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-06-2009, 06:11 PM   #1 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default peculiar date issue

Hey guys I have an interesting date issue.

I'm trying to store birthdays. The MYSQL column is set as INT(10) and the name of the column is bday.

I have 3 dropdowns: month, day, year.

I check that all the info is correct before I convert the data into timestamp for the database table.

PHP Code:
$bday  mktime(000$u_month$u_day$u_year); 
$bday is now in timestamp format.

So if my bday is: June 10 1990 it goes in as: 6, 10, 1990 respectively.

When I log off my site and come back, it seems to pull the data out with one day off, but the rest of the data is correct.

So I would get: 6 9 1990.

Here's the code when I pull it out of the DB:

PHP Code:
// MYSQL QUERY SNIPPET

$g_bday    $row["bday"];
$g_month date("n",$g_bday);
$g_day    date("j",$g_bday);
$g_year    date("Y",$g_bday); 

This gives me again: 6 9 1990


It is just sooo very weird that the day is always one off.

But everything else, MONTH or YEAR goes in and out perfectly.

If I change the day to 25, then I get back 24...

Do you guys have any idea why it does this?

I kept the code pretty short because I think most of you could figure out what I'm doing, and I don't beleive there's much more that I really need to show you but if you need any more code, let me know...
allworknoplay is offline  
Reply With Quote
Old 06-06-2009, 06:29 PM   #2 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Some more info.

I made my birthday: july 15 1978. Here is the mktime data that goes into the DB.

$bday = mktime(0, 0, 0, 7, 15, 1978);
$bday becomes: 269323200

Before DB INSERT
269323200 <-- mktime version of: 7 15 1978

I check the DB to make sure it has the same data and it does.

DB
269323200 <--- Same as above

I then log off, and back on to pull the data out and make sure the data hasn't changed, and it has not.

OUT
269323200 <--- Same consistent data.

But when I use the date() function, it shows: 7 14 1978

$date = date("n j, Y ",$bday);


CRAZY!!!!

WHY!!!??
allworknoplay is offline  
Reply With Quote
Old 06-06-2009, 06:43 PM   #3 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Hmmm I think I might be getting somewhere.

I changed my bday to July 1st 1978 to see what would happen.

The result is that upon logging in, it now shows June 31st 1978.


very very interesting...
allworknoplay is offline  
Reply With Quote
Old 06-06-2009, 06:49 PM   #4 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Ok guys, I figured it out, it was a timzezone issue.

You see, up in my header file, I have this:

date_default_timezone_set("US/New_York");


Because my server is located in Utah which is 2 hours behind.

Anyways, the LOGIN page doesn't call the header file just yet, so it was using the Utah server timestamp. Once I called the timezone_set function above in the login page itself, it is now correct.
allworknoplay is offline  
Reply With Quote
Old 06-09-2009, 12:39 AM   #5 (permalink)
The Contributor
 
Join Date: Jun 2009
Location: Seattle, WA
Posts: 76
Thanks: 1
rguy84 is on a distinguished road
Default

very interesting, I was going to suggest maybe it was a leap year bug
Send a message via AIM to rguy84 Send a message via MSN to rguy84 Send a message via Yahoo to rguy84 Send a message via Skype™ to rguy84
rguy84 is offline  
Reply With Quote
Old 06-09-2009, 12:57 AM   #6 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by rguy84 View Post
very interesting, I was going to suggest maybe it was a leap year bug
More like a bug in my noggin...

allworknoplay is offline  
Reply With Quote
Old 06-09-2009, 01:01 AM   #7 (permalink)
The Contributor
 
Join Date: Jun 2009
Location: Seattle, WA
Posts: 76
Thanks: 1
rguy84 is on a distinguished road
Default

lol, I would never know that. TBH I don't even know where my server is exactly...
Send a message via AIM to rguy84 Send a message via MSN to rguy84 Send a message via Yahoo to rguy84 Send a message via Skype™ to rguy84
rguy84 is offline  
Reply With Quote
Old 06-09-2009, 01:05 AM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Maybe it emigrated whilst you weren't looking. It realises you don't know and moves itself to a warmer climate every 6 months.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-09-2009, 08:06 AM   #9 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
Maybe it emigrated whilst you weren't looking. It realises you don't know and moves itself to a warmer climate every 6 months.
lol

(grrrr char limit)
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Font color for key based on modif date ? Peuplarchie General 1 04-14-2009 01:37 PM
Frustrating PNG Issue on IE 6 aristoworks XHTML, HTML, CSS 5 11-10-2008 08:18 AM
help me figure out this date thing sarmenhb Absolute Beginners 5 09-15-2008 04:20 PM
Need more ideas for date and time class Wildhoney General 2 01-18-2008 02:22 PM
converting to mysql date format harryhood Absolute Beginners 1 08-21-2005 03:57 AM


All times are GMT. The time now is 09:59 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design