Jump to content


Photo

date function problems


  • Please log in to reply
9 replies to this topic

#1 cows

cows
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 October 2006 - 06:13 AM

Hi,

I am pretty new to php and I have a problem I can't quite figure out.  I am not sure if I am misunderstanding the date() function or there is something else I am missing. 

I have this time stamp: 1159660803

In the time stamp converter it says Sun, 1 Oct 2006 00:00:03 UTC

When i try get that from the date() function using

date('l dS \of F Y h:i:s A',  1159660803);

I get a date/time and hour out (Sunday 01st of October 2006 01:00:03 AM)

I need to get the time in the time stamp, is there something I am doing wrong or not quite understanding?  The server is in the UK if that makes any difference.

Any help would be appreciated, I have spent all night trying to figure out what I am doing wrong. :(


#2 trillion

trillion
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 October 2006 - 06:56 AM

what output are you looking for exactly?

do you want this part: 01:00:03 AM

to look like this: 00:00:03 UTC

#3 cows

cows
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 October 2006 - 07:00 AM

Yes, sorry.  I need it to read 00:00:03.

#4 pndof12006

pndof12006
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 16 October 2006 - 07:11 AM

use this excat code
<? echo  date('i:s',  1159660803);?>

or if you need the hour in there use this:
<? echo  date('h:i:s',  1159660803);?>[\code]


#5 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 October 2006 - 07:17 AM

.. that doesn't solve his problem at all.

i imagine it's just a one-hour offset between server time and the timezone you expect it to be in.  try adding "O" (uppercase o) to your date() function and see if the server spits back UTC or if it's off of GMT.

#6 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 16 October 2006 - 08:06 AM

http://www.php.net/date

e Timezone identifier (added in PHP 5.1.0) Examples: UTC, GMT, Atlantic/Azores
SA PHP Archives - www.phparchives.za.org

#7 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 October 2006 - 08:08 AM

keep in mind (as xsist's post itself says) that 'e' will only work for fairly new versions of PHP.

#8 cows

cows
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 October 2006 - 08:24 AM

Thank you.

I never realised the date function formatted the dates using the server's time zone settings and daylight saving settings.  I thought it would format the date as-is, UCT.

Is there anyway I can get the formatted date in UCT with that date function or another function?

#9 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 16 October 2006 - 08:43 AM

Read the manual entry at http://www.php.net/date. If it doesn't help you then check out the posts below it. You'll normally find your solution in the user posted comments.


This may work....
<?php
echo date('D, j M Y h:i:s',  1159660803 - date('Z'));

// or

date_default_timezone_set('UTC');
echo date('D, j M Y h:i:s',  1159660803)

?>

SA PHP Archives - www.phparchives.za.org

#10 cows

cows
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 October 2006 - 08:56 AM

This may work....

<?php
echo date('D, j M Y h:i:s',  1159660803 - date('Z'));

// or

date_default_timezone_set('UTC');
echo date('D, j M Y h:i:s',  1159660803)

?>


The first solution worked perfectly.  Thank you very much.  I didn't want to use the date_default_timezone_set() because the server doesn't support that yet.

Thank you for all the replies, they are much appreciated.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users