#1 (permalink)  
Old 02-14-2006, 03:32 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,445
Problem with timestamps

I'm working on a PHP project that uses timestamps in a lot of places. I'm having some trouble with the conversions between dates/times and UNIX timestamps, though, and I'm not sure where my problem lies.

Here is an example of some of the code I'm using (this is a converter I built to help myself out and to test my conversions):
PHP Code:
<?php

extract
($_POST);
if(
$submit == "->") {
    
$timestamp strtotime($date);
}
elseif(
$submit == "<-") {
    
$date date("m/d/Y \a\\t G:i:s"$timestamp);
}

echo 
"
<form name='convert' method='POST' action='timestamp.php'>
<table style='background-color:#000069;font-size:10px;'>
    <tr>
        <td>Enter a date string:</td>
        <td><input type='text' name='date'"
;
if(isset(
$date)) {
    echo 
" value='$date'";
}
echo 
" /></td>
        <td>
            <input type='submit' name='submit' value='->' />
        </td>
        <td>
            <input type='submit' name='submit' value='<-' />
        </td>
        <td>Or Enter a timestamp:</td>
        <td><input type='text' name='timestamp'"
;
if(isset(
$timestamp)) {
    echo 
" value='$timestamp'";
}
echo 
" /></td>
    </tr>
</table>"
;

?>
The problem is, when I type in a date/time, and convert it to a timestamp, I get what looks like a valid timestamp. However, if I convert that same timestamp back to a date/time, then I lose three hours somewhere.

Example:
Let's say I type:
Code:
02/14/2006 at 23:59:00
into the first box. Then, I convert that into a timestamp. I get the result "1139968740".

If I then convert that timestamp back into a date/time string, I get:
Code:
02/14/2006 at 20:59:00
I'm assuming it has something to do with the fact that I am not specifying a timezone when I convert these things, but I'm not sure how to correct this problem.

Any thoughts?
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote

  #2 (permalink)  
Old 02-21-2006, 08:54 AM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
I'm not exactly sure!

But did you try your converter with mktime()? mktime() returns the current unix timestamp. It should give you an idea if it works - or not. :-)
Reply With Quote
  #3 (permalink)  
Old 04-15-2006, 06:58 AM
Registered User
 
Join Date: Mar 2006
Posts: 12
Server time

I'm in Florida and I helped someone was using a server that was set to Pacific time. I had to adjust for the server's time setting.

It appears that might be what is going on.

I can't remember exactly how to "offset" for the time zone. I only had to do it that one time.
__________________
(\ /)
(o.O)
(>< )
/_|_\


May bunny optain, world domination.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
showLayer function, layer position problem ruthann Programming and Scripting 3 03-19-2006 11:13 AM
Background colour not displaying in Firefox... CSS problem? christhorn Programming and Scripting 4 02-02-2006 04:29 PM
DWMX/Photoshop problem fatsi Programming and Scripting 4 04-24-2005 05:55 PM
CSS, Dhtml layer problem supermeganinjan Programming and Scripting 0 02-17-2005 10:02 PM
Problem with template in dreamweaver Mercury Programming and Scripting 0 02-01-2005 09:14 PM


All times are GMT -5. The time now is 05:18 PM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter