Re: [PHP] Re: Formating datevariables...

2002-07-24 Thread Ragnar

Hi, i dont know if im always going to use mysql, thow your solution to my
problem will be something like this:

SELECT DATE_FORMAT( endret_dato, \%d%m%Y\ ) as endret_dato
, headline
, news
from rnr_news
order by endret_dato desc
limit  . $index . , . ($index+10));

Thanx for your help!

-R

John Holmes [EMAIL PROTECTED] wrote in message
01c232b4$11419d10$b402a8c0@mango">news:01c232b4$11419d10$b402a8c0@mango...
  Thanx for the help..
 
  I ended up with this solution ;)
 
  $dag = substr ( $row['endret_dato'], 7, 2 );
  $mnd = substr ( $row['endret_dato'], 4, 2 );
  $aar = substr ( $row['endret_dato'], 0, 4 );
 
  date (dmY, mktime(0,0,0,$mnd,$dag,$aar) )

 Did you even read the replies? Why are you going to do a bunch of string
 manipulation, mktime, and date calls in PHP when you can just use
 DATE_FORMAT() in your query and get exactly what you want without any
 additional work by PHP?

 Take a little time and Read Chapter 6 of the MySQL manual. It will save
 you a ton of work later on...

 ---John Holmes...


  -R
 
  Ragnar [EMAIL PROTECTED] wrote in message
  [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
   I have a column in a mysql table with a timestamp. The value of this
  column
   is for instance:
  
   20020722185242
  
   How do i change the format on this to DDMM (22072002) in php?
  
   Thanx
  
   -R
  
  
 
 
 
  --
  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




[PHP] Re: Formating datevariables...

2002-07-23 Thread Ragnar

Thanx for the help..

I ended up with this solution ;)

$dag = substr ( $row['endret_dato'], 7, 2 );
$mnd = substr ( $row['endret_dato'], 4, 2 );
$aar = substr ( $row['endret_dato'], 0, 4 );

date (dmY, mktime(0,0,0,$mnd,$dag,$aar) )

-R

Ragnar [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 I have a column in a mysql table with a timestamp. The value of this
column
 is for instance:

 20020722185242

 How do i change the format on this to DDMM (22072002) in php?

 Thanx

 -R





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




RE: [PHP] Re: Formating datevariables...

2002-07-23 Thread John Holmes

 Thanx for the help..
 
 I ended up with this solution ;)
 
 $dag = substr ( $row['endret_dato'], 7, 2 );
 $mnd = substr ( $row['endret_dato'], 4, 2 );
 $aar = substr ( $row['endret_dato'], 0, 4 );
 
 date (dmY, mktime(0,0,0,$mnd,$dag,$aar) )

Did you even read the replies? Why are you going to do a bunch of string
manipulation, mktime, and date calls in PHP when you can just use
DATE_FORMAT() in your query and get exactly what you want without any
additional work by PHP?

Take a little time and Read Chapter 6 of the MySQL manual. It will save
you a ton of work later on...

---John Holmes...


 -R
 
 Ragnar [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  I have a column in a mysql table with a timestamp. The value of this
 column
  is for instance:
 
  20020722185242
 
  How do i change the format on this to DDMM (22072002) in php?
 
  Thanx
 
  -R
 
 
 
 
 
 --
 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] Re: Formating datevariables...

2002-07-23 Thread Cameron McKay

Sure using MySQL specific calls is faster but makes you more dependant 
on MySQL and thus makes your application less portable to other databases.

Cameron


John Holmes wrote:
 
 
 Did you even read the replies? Why are you going to do a bunch of string
 manipulation, mktime, and date calls in PHP when you can just use
 DATE_FORMAT() in your query and get exactly what you want without any
 additional work by PHP?
 
 Take a little time and Read Chapter 6 of the MySQL manual. It will save
 you a ton of work later on...
 
 ---John Holmes...
 
 
 


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




RE: [PHP] Re: Formating datevariables...

2002-07-23 Thread John Holmes

 Sure using MySQL specific calls is faster but makes you more dependant
 on MySQL and thus makes your application less portable to other
databases.
 
 Cameron

Of course. It depends on your application. I know I'm only going to use
MySQL for the programs I'm doing now, so I can use this _faster_ method.


I felt weird about saying it was faster before, so I did some
benchmarking to make sure I could back up what I was saying. Using these
two functions:

function sql_method()
{
$query = SELECT DATE_FORMAT(date_column,'%d%m%Y') FROM benchmark;
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$field = $row[0];
}

return;
}

function php_method()
{
$query = SELECT date_column+0 FROM benchmark;
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$dag = substr ( $row[0], 6, 2 );
$mnd = substr ( $row[0], 4, 2 );
$aar = substr ( $row[0], 0, 4 );

$field = date (dmY, mktime(0,0,0,$mnd,$dag,$aar));
}

return;
}

There were 1000 rows in the one column table, the single column being a
random date in the standard MySQL format. Each function was run 10
times.

Results:

SQL/PHP Date Manipulation   total time  average iteration time  
100% SQL Method 18ms0.0175564  
279% PHP Method 49ms0.0489336  

Your results may vary. I used some benchmark class by Sebastian
Bergmann.

---John Holmes...


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




[PHP] Re: Formating datevariables...

2002-07-22 Thread David Robley

In article [EMAIL PROTECTED], [EMAIL PROTECTED] 
says...
 I have a column in a mysql table with a timestamp. The value of this column
 is for instance:
 
 20020722185242
 
 How do i change the format on this to DDMM (22072002) in php?
 
 Thanx
 
 -R

You can do it as you get it out of the db - see DATEFORMAT

Cheers
-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

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