Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-16-2008, 02:08 AM mysql datetime help
Extreme Talker

Posts: 189
Trades: 0
i use mysql to use datetime and it stores this

Code:
2008-06-15 05:49:08
i read it in from the database and parse it through

PHP Code:
function formatDate($val)
  {
      list(
$date$time) = explode(" "$val);
      list(
$year$month$day) = explode("-"$date);
      list(
$hour$minute$second) = explode (":"$time);
      return 
date("l, m.j.y @ H:ia"mktime($hour$minute$second$month$day$year));
  } 
how do i get it to convert the datetime to another timezone in the php code.
simster is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-16-2008, 05:47 AM Re: mysql datetime help
Skilled Talker

Posts: 71
Trades: 0
The easiest way is to not use datetime.

Just use INT(11) and use time() as the value. You can then format that with the date() function.

From there, you can make a little function using mktime() or something to adjust for different timezones.
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
Old 06-16-2008, 06:05 AM Re: mysql datetime help
Extreme Talker

Posts: 189
Trades: 0
Thanks but I don't think that will work. Most of the code I'm using I got online and it works, I just would like to know how to change the datetime after it reads it in.

Im might also make it so they can pick their timezone.
simster is offline
Reply With Quote
View Public Profile
 
Old 06-16-2008, 09:47 AM Re: mysql datetime help
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
http://www.google.com/search?q=php+timezone

Quote:
list($year, $month, $day) = explode("-", $date);
2008-06-15 05:49:08 => you get
year = 2008
month = 06
day = 15 05:49:08

Quote:
list($hour, $minute, $second) = explode (":", $time);
hour = 2008-06-15 05
minute = 49
second = 08

well... this is not ok

make a print_r to see your results and change some things
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 06-16-2008, 12:45 PM Re: mysql datetime help
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
Try this:

Code:
<?
$timezone = -5;

echo gmdate("y/m/j H:i A", time() + 3600 * ($timezone + date("I")));

?>
This takes the timezone set in the variable (Eastern in this case) and adds or takes away the correct number of hours depending on the timezone. The finial part will adjust according to daylight savings time.

choskins102 is offline
Reply With Quote
View Public Profile
 
Old 06-16-2008, 03:07 PM Re: mysql datetime help
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
And why don't you use the date formatting functions of your db ?
Let the field in a datetime format, and use date_format(field_name,'format') in your query:
http://dev.mysql.com/doc/refman/5.0/...on_date-format
Quote:
SELECT DATE_FORMAT('1900-10-04 22:23:00',
-> '%D %y %a %d %m %b %j');
-> '4th 00 Thu 04 10 Oct 277'
And if you want control over the timezone, then turn yourself to postgresql. It does support a "datetime with timezone" column type, which mysql simply don't do.
http://www.postgresql.org/docs/8.3/s...-datetime.html
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 06-16-2008 at 03:12 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-16-2008, 03:53 PM Re: mysql datetime help
Extreme Talker

Posts: 189
Trades: 0
I use yahoo webhosting for my website, and they have a mysql server I can use. That is why I cant change to the database you mentioned.
simster is offline
Reply With Quote
View Public Profile
 
Old 06-17-2008, 05:00 AM Re: mysql datetime help
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Ok, in that case, you have to handle the timezone in PHP, but I never done it before.

But for the date_format() function, it's a standard function that exists at least since mysql 3.0, so don't be afrais of using it.
It will be much easier than parsing a string in PHP, and more effective in terms of system resources.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to mysql datetime help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.57709 seconds with 12 queries