Current location: Hot Scripts Forums » Programming Languages » PHP » Convert to time from a string


Convert to time from a string

Reply
  #1 (permalink)  
Old 09-25-06, 03:27 PM
Godwin Godwin is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Question Convert to time from a string

Hi,

Ok this may have a simple solution but I couldn't get it work right.

I have 2 columns in the schedule table (hours,mins), which stores the values entered from a form. This would represent the time in singapore format.

My problem is that I want to first convert the singaporean time(GMT +8) to my local time(sri lanka GMT +5.5). For that I need to convert it to GMT first then using offsets I can calculate my local time. So I substract 28800 seconds from the singapore time and now I have the GMT time I can simply convert that to my time zone. But how do I first get the values from hours and mins columns and store it in a variable in time format?


This code below is based on my local time and calculates correctly both in gmt and singapore time.

PHP Code:

$srilanka_time time();

$gmt $srilanka_time - (19800);

$singapore_time $gmt + (28800);
echo 
'GMT is: '.date('H:i'$gmt); 
echo 
'Singapore time is: '.date('H:i'$singapore_time); 

This code below is what I have done to get the GMT time based on singapore time.

PHP Code:

$singapore_time =  //should get values from $row_Recordset1['hours'] and

//$row_Recordset1['mins']

$gmt $singapore_time - (28800);

echo 
'GMT is: '.date('H:i'$gmt); 
As you can see I want to get the correct time format which will be stored in $singapore_time variable given the following values:
$row_Recordset1['hours']
$row_Recordset1['mins']

Can anyone please help me with this ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-25-06, 06:15 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
to get the GMT date, you just have to use gmdate, this automaticly converts the local time to gmt.

to convert it back to singapore time, use the mktime() function: you enter the hours, minutes and seconds and it will create a new time. for you this could look like this:
PHP Code:

$gmt gmdate("H:i");

$singapore_time date("H:i"mktime(gmdate("H")+5gmdate("i")+30gmdate("s"), gmdate("m"), gmdate("d"), gmdate("Y"))); 
maybe there's a simpeler sollution, but this is one i just found, while looking on www.php.net,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-26-06, 01:25 AM
Godwin Godwin is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Hey UnrealEd, thanks for you code.
That worked!

I had to modify a bit so that it takes the values hours and mins from the table. I managed to get it working by refering the links you gave.
I used:
mktime($row_Recordset1['hours'],$row_Recordset1['mins']);

Cool man
thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert each character in string to array robbydweb PHP 9 06-21-09 12:36 AM
how to convert cookie to string mathfxr PHP 4 06-06-06 08:12 AM
how to convert object into string mathfxr ASP 0 03-01-05 10:38 PM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 08:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.