TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   peculiar date issue (http://www.talkphp.com/absolute-beginners/4489-peculiar-date-issue.html)

allworknoplay 06-06-2009 06:11 PM

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 06-06-2009 06:29 PM

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 06-06-2009 06:43 PM

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 06-06-2009 06:49 PM

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.

rguy84 06-09-2009 12:39 AM

very interesting, I was going to suggest maybe it was a leap year bug

allworknoplay 06-09-2009 12:57 AM

Quote:

Originally Posted by rguy84 (Post 25088)
very interesting, I was going to suggest maybe it was a leap year bug

More like a bug in my noggin...

:-D

rguy84 06-09-2009 01:01 AM

lol, I would never know that. TBH I don't even know where my server is exactly...

Wildhoney 06-09-2009 01:05 AM

Maybe it emigrated whilst you weren't looking. It realises you don't know and moves itself to a warmer climate every 6 months.

sketchMedia 06-09-2009 08:06 AM

Quote:

Originally Posted by Wildhoney (Post 25091)
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 :-D

(grrrr char limit)


All times are GMT. The time now is 01:06 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0