Re: [PHP] Unix date (even more bazaar)

2007-12-30 Thread Richard Lynch
Spacing and/or control (unprintable) characters could easily be
messing you up.

Use something like:

$l = strlen($input);
for ($i = 0; $i  $l; $i++){
  echo $i: $input[$i] (, ord($input[$i]), )br /\n;
}
to see what you're getting.

On Fri, December 28, 2007 5:08 pm, tedd wrote:
 At 6:01 PM -0500 12/28/07, tedd wrote:
Hi gang:

This really bazaar

Here's the code and demo:

http://webbytedd.com/c/unix-time1/index.php

If I cut/paste the following string as-is into the Input Date
portion of the form:

10-18-2009 00:00:00

It works and returns a UNIX timestamp of 1255885200

However, if I cut/paste the following string as-is into the Input
Date portion of the form:

10-18-2009 00:00:00

It doesn't work and returns a UNIX timestamp of .

Am I going mad? What the hell is the difference between these two
 stings?

Arr  I knew this day would come.

tedd


 As I feared, the email translation made both strings identical -- so
 this won't work for those trying it.

 BUT, I do have two strings that look identical but aren't.

 I hate it when things like this happen.

 Cheers,

 tedd
 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date (even more bazaar)

2007-12-30 Thread tedd

At 7:07 PM -0600 12/30/07, Richard Lynch wrote:

Spacing and/or control (unprintable) characters could easily be
messing you up.

Use something like:

$l = strlen($input);
for ($i = 0; $i  $l; $i++){
  echo $i: $input[$i] (, ord($input[$i]), )br /\n;
}
to see what you're getting.


Richard:

As usual, you are exactly right.

I found that somehow a gremlin had crept in -- I still don't 
understand how, but it did. So, I stepped through the string similar 
to what you did and replaced everything that wasn't supposed to be 
there.


Interesting that making a text file with the string and looking at it 
via a Hex Editor, I found that the gremlin was a 0A (new line), but 
when it was on the server, it was two characters (High ASCII 
194/160) -- very strange.


In any event, I fixed it. I didn't have the time to run down why.

Thanks,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date (even more bazaar)

2007-12-29 Thread tedd

Yeah, and to what bazaar are you going, old man?

Look, I'm so loopy right now, I'm top-posting.  How bizarre

/Dan


Ohhh, I hate it when that happens -- but, I have had even more 
embarrassing moments.


As to the problem I posted about strings being different, it was a 
gremlin I found in the string. A hex edit of the file showed that the 
space between the date and time, which should have been a space (20) 
was actually a new line (0A) character.


Oh well, at least I found it.

Thanks all.

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date

2007-12-28 Thread Daniel Brown
On Dec 28, 2007 10:46 AM, tedd [EMAIL PROTECTED] wrote:
 Hi gang:

 Using:

 $unix_in = 1255845600;

 echo(date(M d, Y h:i:s a,$unix_in));

 On one sever, produces: Oct 18, 2009 02:00:00 am

 But on another sever, produces: Oct 18, 2009 12:00:00 am

 This difference appears to be a combination of time-zone and
 daylight-savings considerations. In other words, the function
 date() looks at the server's time (whatever that is set for, right or
 wrong) and uses that for the calculation.

 So, what's the best method in keeping things consistent across
 servers? Is there one?

?
if(function_exists(date_default_timezone_set)) {
date_default_timezone_set('UTC');
}

$unix_in = 1255845600;

echo date(M d, Y h:i:s a,$unix_in).\n;
?

It requires PHP 5 = 5.1.0, hence the function_exists() condition.


-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date

2007-12-28 Thread Nathan Nobbe
On Dec 28, 2007 10:46 AM, tedd [EMAIL PROTECTED] wrote:

 Hi gang:

 Using:

 $unix_in = 1255845600;

 echo(date(M d, Y h:i:s a,$unix_in));

 On one sever, produces: Oct 18, 2009 02:00:00 am

 But on another sever, produces: Oct 18, 2009 12:00:00 am

 This difference appears to be a combination of time-zone and
 daylight-savings considerations. In other words, the function
 date() looks at the server's time (whatever that is set for, right or
 wrong) and uses that for the calculation.

 So, what's the best method in keeping things consistent across
 servers? Is there one?


assuming you have the
date.timezone
php.ini directive set appropriately on each system and they are in different
timezones, the values will not be the same.  if you want to get the same
time
you can go for GMT;

$unix_in = 1255845600;
echo(gmdate(M d, Y h:i:s a,$unix_in));

-nathan


RE: [PHP] Unix date

2007-12-28 Thread bruce
i'm pretty sure you can sync/link to a ntp server to accurately track the
time...



-Original Message-
From: tedd [mailto:[EMAIL PROTECTED]
Sent: Friday, December 28, 2007 7:47 AM
To: PHP
Subject: [PHP] Unix date


Hi gang:

Using:

$unix_in = 1255845600;

echo(date(M d, Y h:i:s a,$unix_in));

On one sever, produces: Oct 18, 2009 02:00:00 am

But on another sever, produces: Oct 18, 2009 12:00:00 am

This difference appears to be a combination of time-zone and
daylight-savings considerations. In other words, the function
date() looks at the server's time (whatever that is set for, right or
wrong) and uses that for the calculation.

So, what's the best method in keeping things consistent across
servers? Is there one?

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date

2007-12-28 Thread Børge Holen
On Friday 28 December 2007 16:46:46 tedd wrote:
 Hi gang:

 Using:

 $unix_in = 1255845600;

 echo(date(M d, Y h:i:s a,$unix_in));

 On one sever, produces: Oct 18, 2009 02:00:00 am

 But on another sever, produces: Oct 18, 2009 12:00:00 am

 This difference appears to be a combination of time-zone and
 daylight-savings considerations. In other words, the function
 date() looks at the server's time (whatever that is set for, right or
 wrong) and uses that for the calculation.

 So, what's the best method in keeping things consistent across
 servers? Is there one?

I almost took to a baseballbat, till I remembered to change php.ini to co run 
two servers. Of course doing this in severeal servers all across the world 
probably would result in some timeerror somewhere, but it did the job for me 
EASY!!



 Cheers,

 tedd

 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com



-- 
---
Børge Holen
http://www.arivene.net

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date

2007-12-28 Thread Jochem Maas
tedd schreef:
 Hi gang:
 
 Using:
 
 $unix_in = 1255845600;
 
 echo(date(M d, Y h:i:s a,$unix_in));
 
 On one sever, produces: Oct 18, 2009 02:00:00 am
 
 But on another sever, produces: Oct 18, 2009 12:00:00 am
 
 This difference appears to be a combination of time-zone and
 daylight-savings considerations. In other words, the function date()
 looks at the server's time (whatever that is set for, right or wrong)
 and uses that for the calculation.
 
 So, what's the best method in keeping things consistent across servers?
 Is there one?

not sure exactly what your requirements are (and I can easily lose days
f'ing around with these kinds of dates issues) but have you checked out
gmdate() and it's friends (gm = GMT)?

http://php.net/manual/en/function.gmdate.php

 
 Cheers,
 
 tedd
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date

2007-12-28 Thread tedd

At 7:45 PM +0100 12/28/07, Børge Holen wrote:

On Friday 28 December 2007 16:46:46 tedd wrote:
  So, what's the best method in keeping things consistent across

 servers? Is there one?


I almost took to a baseballbat, till I remembered to change php.ini to co run
two servers. Of course doing this in severeal servers all across the world
probably would result in some timeerror somewhere, but it did the job for me
EASY!!


Well, I'm glad it was easy for you, but this has 
been, and remains, confusing and frustrating for 
me.


Here's the problem if anyone cares to stress themselves.

Here is the code and demo:

http://webbytedd.com/c/unix-time1/index.php

It works for me on my server.

However, when I use the exact same function for a 
client on his server and enter:


10-18-2009 00:00:00

The function changes the date to:

10-18-2009 12:00:00

What's going on here?

Cheers,

tedd

PS: I have no control over the php.in file.

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date (even more bazaar)

2007-12-28 Thread tedd

Hi gang:

This really bazaar

Here's the code and demo:

http://webbytedd.com/c/unix-time1/index.php

If I cut/paste the following string as-is into the Input Date 
portion of the form:


10-18-2009 00:00:00

It works and returns a UNIX timestamp of 1255885200

However, if I cut/paste the following string as-is into the Input 
Date portion of the form:


10-18-2009 00:00:00

It doesn't work and returns a UNIX timestamp of .

Am I going mad? What the hell is the difference between these two stings?

Arr  I knew this day would come.

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date (even more bazaar)

2007-12-28 Thread tedd

At 6:01 PM -0500 12/28/07, tedd wrote:

Hi gang:

This really bazaar

Here's the code and demo:

http://webbytedd.com/c/unix-time1/index.php

If I cut/paste the following string as-is into the Input Date 
portion of the form:


10-18-2009 00:00:00

It works and returns a UNIX timestamp of 1255885200

However, if I cut/paste the following string as-is into the Input 
Date portion of the form:


10-18-2009 00:00:00

It doesn't work and returns a UNIX timestamp of .

Am I going mad? What the hell is the difference between these two stings?

Arr  I knew this day would come.

tedd



As I feared, the email translation made both strings identical -- so 
this won't work for those trying it.


BUT, I do have two strings that look identical but aren't.

I hate it when things like this happen.

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date (even more bazaar)

2007-12-28 Thread Dan
tedd [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

Hi gang:

This really bazaar

Here's the code and demo:

http://webbytedd.com/c/unix-time1/index.php

If I cut/paste the following string as-is into the Input Date portion 
of the form:


10-18-2009 00:00:00

It works and returns a UNIX timestamp of 1255885200

However, if I cut/paste the following string as-is into the Input Date 
portion of the form:


10-18-2009 00:00:00

It doesn't work and returns a UNIX timestamp of .

Am I going mad? What the hell is the difference between these two stings?

Arr  I knew this day would come.

tedd


Hi Tedd, next time you could just reply to your origional thread, you can 
change the subject without making  new thread, it's just harder for other 
people to follow.  Anyway, check out my response about storing and reading 
using GMT, it might help you.


- Dan 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date

2007-12-28 Thread Børge Holen
On Friday 28 December 2007 23:48:21 tedd wrote:
 At 7:45 PM +0100 12/28/07, Børge Holen wrote:
 On Friday 28 December 2007 16:46:46 tedd wrote:
So, what's the best method in keeping things consistent across
 
   servers? Is there one?
 
 I almost took to a baseballbat, till I remembered to change php.ini to co
  run two servers. Of course doing this in severeal servers all across the
  world probably would result in some timeerror somewhere, but it did the
  job for me EASY!!

 Well, I'm glad it was easy for you, but this has
 been, and remains, confusing and frustrating for
 me.

Shouldn't be... two different servers where the timezone in php.ini is set 
different.
It does not do anything useful, EXCEPT giving you the possability to offset/ 
skew the time in php. 

Short version and a hand on explanation:
Say I maintain a machine in seattle and my own here in norway. 9 hours time 
difference. 
These two is handling a site together and the database timestamp has to be the 
same, on a date not yet arrived on the other.
I can now offset one of the machines 9 hour forth or back to fit my need.

of course this only work if you handle one domain (or more in one country). If 
not... you must use the solution presented by the others here.



 Here's the problem if anyone cares to stress themselves.

 Here is the code and demo:

 http://webbytedd.com/c/unix-time1/index.php

 It works for me on my server.

 However, when I use the exact same function for a
 client on his server and enter:

 10-18-2009 00:00:00

 The function changes the date to:

 10-18-2009 12:00:00

 What's going on here?

That was my problem to, till I found the bugger in the ini file:
[Date]
; Defines the default timezone used by the date functions
date.timezone = 0

that is the line you are looking for... or would if you had access to it.
with the lines the other nice ppl provided, you do exactly the same, just not 
system wide.


 Cheers,

 tedd

 PS: I have no control over the php.in file.

shoot the administrator..
or add a code to offset the time


 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com



-- 
---
Børge Holen
http://www.arivene.net

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date

2007-12-28 Thread Daniel Brown
On Dec 28, 2007 5:48 PM, tedd [EMAIL PROTECTED] wrote:
[snip!]
 Here is the code and demo:

 http://webbytedd.com/c/unix-time1/index.php

 It works for me on my server.
[snip!]

Well, if you don't want to change the timezone at runtime like I
suggested this morning, you could do something with the date(O);
switch to see the difference.

THIS IS UNTESTED, AND BEING TYPED BY AN EXHAUSTED GEEK WHO'S READY
FOR NEW YEARS' VACATION

?php  // == functions =--

function dateToUnix($datetime)// in the form of 12-25-2007 00:00:00
  {

  $parts = explode(' ', $datetime);  // separate 12-25-2007 from 00:00:00
  if (count($parts) != 2)
{
return;
}

  $date_parts = explode('-', $parts[0]);  // separate 12-25-2007
  if (count($date_parts) != 3)
{
return;
}

  $time_parts = explode(':', $parts[1]);  // separate 00:00:00
  if (count($time_parts) != 3 )
{
return;
}

  $my_timezone = +0500; // To denote EST (GMT -0500) - Change to
whatever you want.

  if(date(O)  $my_timezone)
{
  substr($my_timezone,0,1) == -  substr(date(O),0,1) == -
? $time_parts[0] = (($time_parts[0] + date(O)) - $my_timezone)
: null;
  substr($my_timezone,0,1) == -  substr(date(O),0,1) == +
?  $time_parts[0] = (($time_parts[0] - date(O)) - $my_timezone)
: null;
  substr($my_timezone,0,1) == +  substr(date(O),0,1) == +
? $time_parts[0] = (($time_parts[0] - date(O)) + $my_timezone)
: null;
  substr($my_timezone,0,1) == +  substr(date(O),0,1) == -
? $time_parts[0] = (($time_parts[0] + date(O)) + $my_timezone)
: null;
}

  return mktime($time_parts[0], $time_parts[1], $time_parts[2],
  $date_parts[0], $date_parts[1], $date_parts[2],-1);

  }

echo date(m/d/Y H:i:s,dateToUnix(12-28-2007 18:30:46)).\n;

?

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unix date (even more bazaar)

2007-12-28 Thread Daniel Brown
Yeah, and to what bazaar are you going, old man?

Look, I'm so loopy right now, I'm top-posting.  How bizarre

HAPPY NEW YEAR TO ALL, AND TO ALL SHUT THE HELL UP!

Be safe, happy, and healthy into 2008!

/Dan



On Dec 28, 2007 6:16 PM, Dan [EMAIL PROTECTED] wrote:
 tedd [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  Hi gang:
 
  This really bazaar
 
  Here's the code and demo:
 
  http://webbytedd.com/c/unix-time1/index.php
 
  If I cut/paste the following string as-is into the Input Date portion
  of the form:
 
  10-18-2009 00:00:00
 
  It works and returns a UNIX timestamp of 1255885200
 
  However, if I cut/paste the following string as-is into the Input Date
  portion of the form:
 
  10-18-2009 00:00:00
 
  It doesn't work and returns a UNIX timestamp of .
 
  Am I going mad? What the hell is the difference between these two stings?
 
  Arr  I knew this day would come.
 
  tedd

 Hi Tedd, next time you could just reply to your origional thread, you can
 change the subject without making  new thread, it's just harder for other
 people to follow.  Anyway, check out my response about storing and reading
 using GMT, it might help you.

 - Dan


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php