[PHP-DB] convert date in german format

2003-11-26 Thread Ruprecht Helms
Hi,

how can I convert a date stored in a mysql-database for output
in the german format (dd.mm.yy).

I tried date (d.m.y,$row-from); 

but I still get the english-format stored in the database.
The databasefield is type  date.

Regards,
Ruprecht

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



Re: [PHP-DB] convert date in german format

2003-11-26 Thread Hans Lellelid

how can I convert a date stored in a mysql-database for output
in the german format (dd.mm.yy).
I tried date (d.m.y,$row-from); 
 

the second parameter to date() should be a unix timestamp (integer).  
Did you convert your MySQL date to a timestamp?

Try:

date(d.m.y, strtotime($row-from));

if that doesn't work (strtotime will return -1 if it fails, which will 
end up looking like 31.12.69 when date() renders it), then you may need 
to either a) use MySQL's UNIX_TIMESTAMP() function in your query to 
convert your date to a unix timestamp or b) use preg_match() and 
mktime() to create the unix timestamp from the MYSQL data.

Hans



smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PHP-DB] convert date in german format

2003-11-26 Thread Ignatius Reilly
at the top of your script, do:
setlocale ( LC_TIME, 'de_DE' ) ;
(assumes your machine has German support installed)

HTH
Ignatius
_
- Original Message - 
From: Ruprecht Helms [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, November 26, 2003 16:58
Subject: [PHP-DB] convert date in german format


 Hi,
 
 how can I convert a date stored in a mysql-database for output
 in the german format (dd.mm.yy).
 
 I tried date (d.m.y,$row-from); 
 
 but I still get the english-format stored in the database.
 The databasefield is type  date.
 
 Regards,
 Ruprecht
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

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



Re: [PHP-DB] convert date in german format

2003-11-26 Thread CPT John W. Holmes
From: Ruprecht Helms [EMAIL PROTECTED]
 how can I convert a date stored in a mysql-database for output
 in the german format (dd.mm.yy).

 I tried date (d.m.y,$row-from);

 but I still get the english-format stored in the database.
 The databasefield is type  date.

That's because date() wants a Unix timestamp. MySQL has it's own format.

You have two options. Option 1 is to use DATE_FORMAT() in your query to
retrieve the date already formated. DATE_FORMAT() works similar to the PHP
date() function. Look it up in Chapter 6 of the MySQL Manual.

Option 2 is to use UNIX_TIMESTAMP() in your query to retrieve the MySQL date
formatted as a Unix timestamp. You can then pass this value to the PHP
date() function and format it like you have above.

---John Holmes...

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



Re: [PHP-DB] convert date in german format

2003-11-26 Thread Chris Boget
 That's because date() wants a Unix timestamp. MySQL has it's own format.
 You have two options. Option 1 is to use DATE_FORMAT() in your query to
 retrieve the date already formated. DATE_FORMAT() works similar to the PHP
 date() function. Look it up in Chapter 6 of the MySQL Manual.
 Option 2 is to use UNIX_TIMESTAMP() in your query to retrieve the MySQL date
 formatted as a Unix timestamp. You can then pass this value to the PHP
 date() function and format it like you have above.

Or option 3: strtotime()

Chris

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



Re: [PHP-DB] convert date in german format

2003-11-26 Thread Hans Lellelid

at the top of your script, do:
setlocale ( LC_TIME, 'de_DE' ) ;
(assumes your machine has German support installed)
 

Yes, this is really the right way to do date display for different 
locales, but it also requries that you use the strftime() function 
instead of date().

Like date(), strftime() will expect the second param to be a unix 
timestamp, so you still have to deal with that issue.  strftime() will 
provide much more flexibility in displaying german dates -- e.g. ability 
to have German days of week, month names, etc.

Using MySQL DATE_FORMAT() would work, but it's a hack solution; if you 
ever wanted to create an English version of your site you would have to 
make changes to your data-layer queries -- and that's just not where 
that logic belongs.

Hans

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


Re: [PHP-DB] convert date in german format

2003-11-26 Thread CPT John W. Holmes
From: Hans Lellelid [EMAIL PROTECTED]

 Using MySQL DATE_FORMAT() would work, but it's a hack solution; if you
 ever wanted to create an English version of your site you would have to
 make changes to your data-layer queries -- and that's just not where
 that logic belongs.

So use UNIX_TIMESTAMP and date() or just use strtotime(). Or go all out and
just store the dates in a unix format in an integer column to begin with!
The choice is yours...

---John Holems...

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