Re: [PHP] Windows date(Y/m/d H:i:s) performance

2008-07-30 Thread Andrew Ballard
On Wed, Jul 30, 2008 at 12:11 PM, Richard Lynch [EMAIL PROTECTED] wrote:
 I was profiling some code on my local dev box, and in Windows, the
 biggest time sink for the home page is...

 a call to date(Y/m/d H:i:s)?!
 917 ms???

 Here is what I get in a cygwin shell:
 php -r '$c = 100; $s = microtime(true); for($i = 0; $i  $c; $i++){ $d
 = date(Y/m/d H:i:s); } echo (microtime(true) - $s)/$c, \n; '
 1.0072922205925

 Same results from a DOS prompt, though I have to actually create a
 file as -r didn't seem to work...

 Feel free to change $c to 10 to get a faster answer...

 Can 'date' really take almost a full second to execute in Doze?...

 That seems pretty whack...


I just ran your test code inside Zend Studio under Windows XP and it
printed 0.00044636011123657

Andrew

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



Re: [PHP] echo date('Y-m-d', $mydata-timestamp);

2007-04-24 Thread Richard Lynch
Use the MySQL function that converts timestamp into Unixtime.

Or, better yet, use the MySQL function that outputs exactly the date
format you want, without dinking around with Unix timestamp in the
middle.

http://dev.mysql.com/

Search for date_format() I do believe.

It's gonna be a whole lot like PHP 'date' function, only with % signs,
as I recall.

On Sun, April 22, 2007 1:33 am, John Taylor-Johnston wrote:

 It is actually a generated timestamp in MySQL.
 timestamp(14)
 Now what? I was hoping to avoid:
 |echo substr(|$mydata-timestamp|, 0, 8);

 John

 |Richard Lynch wrote:
 On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote:

 $mydata-timestamp = 20070419162123;

 echo date('Y-m-d', $mydata-timestamp);


 result: 2038-01-18

 ?? What is wrong?? Should be 2007-04-19?


 date() takes a Unix timestamp as its input.

 Unix timestamps are measured as number of seconds from Jan 1, 1970,
 midnight, GMT, the birth of Disco.
 [that last was a joke...]

 You are handing it a pre-formatted date-stamp in MMDDHHIISS
 format...

 You could do something like:
 $t = '20070419162123';
 $year = substr($t, 0, 4);
 $month = substr($t, 4, 2);
 $day = substr($t, 6, 2);
 $hour = substr($t, 8, 2);
 $minutes = substr($t, 10, 2);
 $seconds = substr($t, 12, 2);
 echo date(mktime($month, $day, $year, $hour, $minutes, $seconds));

 I suspect strtotime() *might* handle your input and give you a Unix
 timestamp...

 I also suspect whatever you needed a Unix timestamp for in the first
 place could have been achieved easier before you got painted into
 this
 corner...





-- 
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/browse/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] echo date('Y-m-d', $mydata-timestamp);

2007-04-22 Thread Richard Lynch
On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote:
 $mydata-timestamp = 20070419162123;

 echo date('Y-m-d', $mydata-timestamp);


 result: 2038-01-18

 ?? What is wrong?? Should be 2007-04-19?

date() takes a Unix timestamp as its input.

Unix timestamps are measured as number of seconds from Jan 1, 1970,
midnight, GMT, the birth of Disco.
[that last was a joke...]

You are handing it a pre-formatted date-stamp in MMDDHHIISS format...

You could do something like:
$t = '20070419162123';
$year = substr($t, 0, 4);
$month = substr($t, 4, 2);
$day = substr($t, 6, 2);
$hour = substr($t, 8, 2);
$minutes = substr($t, 10, 2);
$seconds = substr($t, 12, 2);
echo date(mktime($month, $day, $year, $hour, $minutes, $seconds));

I suspect strtotime() *might* handle your input and give you a Unix
timestamp...

I also suspect whatever you needed a Unix timestamp for in the first
place could have been achieved easier before you got painted into this
corner...

-- 
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/browse/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] echo date('Y-m-d', $mydata-timestamp);

2007-04-22 Thread John Taylor-Johnston


It is actually a generated timestamp in MySQL.
timestamp(14)
Now what? I was hoping to avoid:
|echo substr(|$mydata-timestamp|, 0, 8);

John

|Richard Lynch wrote:

On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote:
  

$mydata-timestamp = 20070419162123;

echo date('Y-m-d', $mydata-timestamp);


result: 2038-01-18

?? What is wrong?? Should be 2007-04-19?



date() takes a Unix timestamp as its input.

Unix timestamps are measured as number of seconds from Jan 1, 1970,
midnight, GMT, the birth of Disco.
[that last was a joke...]

You are handing it a pre-formatted date-stamp in MMDDHHIISS format...

You could do something like:
$t = '20070419162123';
$year = substr($t, 0, 4);
$month = substr($t, 4, 2);
$day = substr($t, 6, 2);
$hour = substr($t, 8, 2);
$minutes = substr($t, 10, 2);
$seconds = substr($t, 12, 2);
echo date(mktime($month, $day, $year, $hour, $minutes, $seconds));

I suspect strtotime() *might* handle your input and give you a Unix
timestamp...

I also suspect whatever you needed a Unix timestamp for in the first
place could have been achieved easier before you got painted into this
corner...

  


Re: [PHP] echo date('Y-m-d', $mydata-timestamp);

2007-04-22 Thread Børge Holen
On Sunday 22 April 2007 08:33, John Taylor-Johnston wrote:
 It is actually a generated timestamp in MySQL.
 timestamp(14)

Well, then just use the query to decide how it should look like.
Mysql timestamp is amazingly easy to work with.
whatevertable,date_format(timestamp_table, 'what should it look like') as 
timestamp or use another name if you need both like I do.


 Now what? I was hoping to avoid:
 |echo substr(|$mydata-timestamp|, 0, 8);

 John

 |Richard Lynch wrote:
 |
  On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote:
  $mydata-timestamp = 20070419162123;
 
  echo date('Y-m-d', $mydata-timestamp);
 
 
  result: 2038-01-18
 
  ?? What is wrong?? Should be 2007-04-19?
 
  date() takes a Unix timestamp as its input.
 
  Unix timestamps are measured as number of seconds from Jan 1, 1970,
  midnight, GMT, the birth of Disco.
  [that last was a joke...]
 
  You are handing it a pre-formatted date-stamp in MMDDHHIISS format...
 
  You could do something like:
  $t = '20070419162123';
  $year = substr($t, 0, 4);
  $month = substr($t, 4, 2);
  $day = substr($t, 6, 2);
  $hour = substr($t, 8, 2);
  $minutes = substr($t, 10, 2);
  $seconds = substr($t, 12, 2);
  echo date(mktime($month, $day, $year, $hour, $minutes, $seconds));
 
  I suspect strtotime() *might* handle your input and give you a Unix
  timestamp...
 
  I also suspect whatever you needed a Unix timestamp for in the first
  place could have been achieved easier before you got painted into this
  corner...

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

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



Re: [PHP] echo date('Y-m-d', $mydata-timestamp);

2007-04-22 Thread Jochem Maas
John Taylor-Johnston wrote:
 
 It is actually a generated timestamp in MySQL.
 timestamp(14)
 Now what? I was hoping to avoid:
 |echo substr(|$mydata-timestamp|, 0, 8);

the simplest answer is actually yto make mySQL give you
the data in unix timestamp format in the first place:

SELECT UNIX_TIMESTAMP(my_field) AS my_timestamp FROM foo WHERE id=1;

 
 John
 
 |Richard Lynch wrote:
 On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote:
  
 $mydata-timestamp = 20070419162123;

 echo date('Y-m-d', $mydata-timestamp);


 result: 2038-01-18

 ?? What is wrong?? Should be 2007-04-19?
 

 date() takes a Unix timestamp as its input.

 Unix timestamps are measured as number of seconds from Jan 1, 1970,
 midnight, GMT, the birth of Disco.
 [that last was a joke...]

 You are handing it a pre-formatted date-stamp in MMDDHHIISS format...

 You could do something like:
 $t = '20070419162123';
 $year = substr($t, 0, 4);
 $month = substr($t, 4, 2);
 $day = substr($t, 6, 2);
 $hour = substr($t, 8, 2);
 $minutes = substr($t, 10, 2);
 $seconds = substr($t, 12, 2);
 echo date(mktime($month, $day, $year, $hour, $minutes, $seconds));

 I suspect strtotime() *might* handle your input and give you a Unix
 timestamp...

 I also suspect whatever you needed a Unix timestamp for in the first
 place could have been achieved easier before you got painted into this
 corner...

   
 

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



RE: [PHP] echo date('Y-m-d', $mydata-timestamp);

2007-04-22 Thread Buesching, Logan J
You are misunderstanding what timestamp means.  The value of a timestamp
is from UNIX epoch http://en.wikipedia.org/wiki/Unix_time.  It is
calculated by the number of seconds after January 1st, 1970.  Also note,
that you are overflowing the integer, which is giving you a
http://en.wikipedia.org/wiki/Year_2038_problem Y2K38 problem.

If you want the UNIX timestamp of 4/19/2007 16:21:23, you can do
mktime(16,21,23,4,19,2007);
(http://us.php.net/manual/en/function.mktime.php).

-Logan

-Original Message-
From: John Taylor-Johnston
[mailto:[EMAIL PROTECTED] 
Sent: Sunday, April 22, 2007 2:05 AM
To: PHP-General
Cc: John Taylor-Johnston
Subject: [PHP] echo date('Y-m-d', $mydata-timestamp);

$mydata-timestamp = 20070419162123;

echo date('Y-m-d', $mydata-timestamp);


result: 2038-01-18

?? What is wrong?? Should be 2007-04-19?

-- 
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] if(date(Y-m-d)

2005-01-10 Thread Andrew Kreps
On Mon, 10 Jan 2005 13:08:28 -0500, John Taylor-Johnston
[EMAIL PROTECTED] wrote:
 Hi,
 I would like some help to improve this script. I'm a teacher with a schedule 
 of 17 weeks.
 Instead of using if(date(Y-m-d) = $week3)  I would like to do a for i = 1 
 to 17 and if the current date date(Y-m-d) = week[i] I would like to echo 
 This is week $week[i];
 
 Can someone show me how please?
 
 ?php
 #old code:
 $week1 = 2005-01-17;
 $week2 = 2005-01-24;
 ...
 $week17 = 2005-05-09;
 
 if(date(Y-m-d) = $week3)
 {
 echo this is week 3);
 }
 ?
 

You're actually pretty close.  What I would do is remove the dashes
from the equation and make that date a unique number.  The advantage
of the date format you're using is that the date represented as a
number will always be sequential.  So, if you do this:

$week1 = 20050110;
$week2 = 20050117;
$week3 = 20050124;

if(date(Ymd) = $week1)
{
echo this is week 1;
}

Now you'll have to create your logic in reverse, so that it will
trigger the latest date first, because every date from now until week
17 will be greater than $week1.  So, something like:

if (date(Ymd) = $week17)
{
 echo This is week 17;
}
elseif (date(Ymd) = $week16)
{
echo This is week 16;
}

etc.  

Does that make sense?

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



Re: [PHP] if(date(Y-m-d)

2005-01-10 Thread Andrew Kreps
On Mon, 10 Jan 2005 13:08:28 -0500, John Taylor-Johnston
[EMAIL PROTECTED] wrote:
 Hi,
 I would like some help to improve this script. I'm a teacher with a schedule 
 of 17 weeks.
 Instead of using if(date(Y-m-d) = $week3)  I would like to do a for i = 1 
 to 17 and if the current date date(Y-m-d) = week[i] I would like to echo 
 This is week $week[i];
 
 Can someone show me how please?

Ok, let me take another stab at this and answer the actual question
you asked.  What can I say, I haven't had my coffee this morning.  :)

Try this code:

$weeks = array (20050107, 20050110, 20050115);

for ($i = count($weeks) - 1;  $i = 0;  $i--)
{
if (date (Ymd) = $weeks[$i])
{
print This is week  . ($i + 1);
break;
}
}

It counts backwards, since you'll want to test the latest week first. 
You could count forward in the for loop if you create the weeks array
with the weeks counting down.  I don't particuarly like having a break
in the loop, but it gets the job done.  If you didn't have it in
there, you would see the print statement for every week that has
passed, as opposed to the current one.

Was this a better answer?

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



Re: [PHP] if(date(Y-m-d)

2005-01-10 Thread Travis Conway
Maybe this will help.  Just keep adding to $var[] until you add all your 
weeks.  Then execute it.  This is written to run on the command line, but 
you can replace the \n with br to get your breaks in HTML.

?
   $var = Array();
   $var[] = 2005-01-02;
   $var[] = 2005-01-09;
   $var[] = 2005-01-16;
   $numweeks = count($var);
   echo Number of weeks:  . $numweeks . \n;
   $today = date(Y-m-d);
   for ($i=0;$i$numweeks;$i++) {
   if ($today = $var[$i]) {
   $lastweek = $i + 1;
   }
   }
   echo This is week $lastweek.\n;
?
HTH
Trav
www.pinkbunnysuit.com
- Original Message - 
From: John Taylor-Johnston [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Monday, January 10, 2005 12:08 PM
Subject: [PHP] if(date(Y-m-d) 


Hi,
I would like some help to improve this script. I'm a teacher with a 
schedule of 17 weeks.
Instead of using if(date(Y-m-d) = $week3)  I would like to do a for i 
= 1 to 17 and if the current date date(Y-m-d) = week[i] I would like to 
echo This is week $week[i];

Can someone show me how please?
?php
#old code:
$week1 = 2005-01-17;
$week2 = 2005-01-24;
...
$week17 = 2005-05-09;
if(date(Y-m-d) = $week3)
{
echo this is week 3);
}
?
Thanks,
John
--
John Taylor-Johnston
-
If it's not Open Source, it's Murphy's Law.
'''Collège de Sherbrooke:
ô¿ôhttp://www.collegesherbrooke.qc.ca/languesmodernes/
 - 819-569-2064
 °v°   Bibliography of Comparative Studies in Canadian, Québec and Foreign 
Literatures
/(_)\  Université de Sherbrooke
 ^ ^   http://compcanlit.ca/ T: 819.569.2064

--
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] if(date(Y-m-d)

2005-01-10 Thread Bret Hughes
On Mon, 2005-01-10 at 12:08, John Taylor-Johnston wrote:
 Hi,
 I would like some help to improve this script. I'm a teacher with a schedule 
 of 17 weeks.
 Instead of using if(date(Y-m-d) = $week3)  I would like to do a for i = 1 
 to 17 and if the current date date(Y-m-d) = week[i] I would like to echo 
 This is week $week[i];
 
 Can someone show me how please?
 
 
 ?php
 #old code:
 $week1 = 2005-01-17;
 $week2 = 2005-01-24;
 ...
 $week17 = 2005-05-09;
 
 if(date(Y-m-d) = $week3)
 {
 echo this is week 3);
 }
 ?
 

(Mistakenly sent to the OP only and I could not stand having my code not
seen by all :)  tested in a shell not web page so YMMV.  Now as I look
at it, a valid date in the last week would not work since there was no
end defined.  I added a 18th date and modified the if to  next week
date.  This code should work with no assumptions that today is even in
the range of weeks defined.

You practically wrote it already.  Also you can use a for loop to load
the array of dates.
$m=1;
$d=11;
$y=2005;

//Load week array
$week= array();
for ($i=0; $i= 17; $i++ ) {
$week[$i] = date(Y-m-d,mktime(0, 0, 0, $m  , $d + (7*$i), $y));
}
$today=date(Y-m-d);
for ($i=0; $i= 16; $i++ ){
if ($today =  $week[$i] and $today  $week[$i+1] ){
echo This is week . ($i + 1) .  that began on $week[$i]\n;
exit;
}
}
echo could not find what week $today is in\n;
echo start date is $y-$m-$d\n;
echo end date is $week[17]\n;


HTH

Bret

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



Re: [PHP] if(date(Y-m-d)

2005-01-10 Thread Richard Lynch
 On Mon, 10 Jan 2005 13:08:28 -0500, John Taylor-Johnston
 [EMAIL PROTECTED] wrote:
 Hi,
 I would like some help to improve this script. I'm a teacher with a
 schedule of 17 weeks.
 Instead of using if(date(Y-m-d) = $week3)  I would like to do a for
 i = 1 to 17 and if the current date date(Y-m-d) = week[i] I would
 like to echo This is week $week[i];

 Can someone show me how please?

You could also consider using http://php.net/date with the 'W' (ISO-8601
week number of year, weeks starting on Monday (added in PHP 4.1.0))
argument or 'z'  (The day of the year (starting from 0)) and divide by 7.

You'd need to compute your offset to your 'first' week that you care
about, but...

?php
  //PHP 4.1.0 and up:
  $start_week = date('W', mktime(0, 0, 0, 9, 4, 2005));
  echo This is week: , date('W', mktime(0, 0, 0, 10, 1, 2005)) -
$start_week, BR\n;
?

Depending on what you are doing and how you are already storing dates,
this could be cleaner.

Watch out, though, as you'll have issues on New Year's Eve if that's in
the middle of a 17-week period, as I suspect it is...

You could also just use:
?php
  $start_week = mktime(0, 0, 0, 8, 2, 2005);
  function seconds_to_week($seconds){
return $seconds / (60*60*24*7);
  }
  echo This is week: , seconds_to_week(mktime(0, 0, 0, 9, 17, 2005)),
BR\n;
?

-- 
Like Music?
http://l-i-e.com/artists.htm

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