|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Chrunchy Smarty n00b
Joined: 20 Jun 2004 Posts: 1
|
Posted: Sun Jun 20, 2004 8:28 am Post subject: Probleme mit date_format |
|
|
Hallo,
ich versuche ein Geburtsdatum mit Hilfe von date_format wieder zugeben.
generiert wird der DB-Eintrag mit:
mktime(0,0,0,$_POST[Date_Month],$_POST[Date_Day],$_POST[Date_Year])
Das führt ab Date_Year <1970 zu negativen Werten, die anscheinend date_format nicht behandeln kann, jedenfalls wird bei der Augabe mittels date_format immer das aktuelle Datum angezeigt.
Ist dieses Problem bekannt, oder ist es gar ein Feature? Gibt es dafür eine Lösung?
Thx. _________________ MfG Chrunchy |
|
Back to top |
|
noftinator Smarty n00b
Joined: 26 Jun 2004 Posts: 3
|
Posted: Sun Jun 27, 2004 12:36 am Post subject: Scheint ein PHP-Problem zu sein |
|
|
Hallo,
date_format nutzt die PHP-Funktion strftime, und diese gibt bei negativen Werten auch nichts zurück.
[php:1:7709558fd8]<?php
print strftime('%d.%m.%Y', -142477200);
?>[/php:1:7709558fd8]
Lösung: Eine eigene Funktion schreiben, die die date-Funktion von PHP verwendet. Naja eher ein Workaround als ne Lösung
[php:1:7709558fd8]<?php
// function renderDate
function renderDate($iTimestamp, $sFormat) {
return date($sFormat, $iTimestamp);
}
// Smarty-Instanz erzeugen
// (template-Pfad etc lass ich mal weg)
$oSmarty = new Smarty;
$oSmarty->register_modifier("own_date_format", "renderDate");
$oSmarty->assign('TIMESTAMP', mktime(0,0,0,6,27,1965));
$oSmarty->display('test_dateformat.tpl.html');
?>[/php:1:7709558fd8]
Und in der test_dateformat.tpl.html steht folgendes:
Code: | Timestamp: { $TIMESTAMP }
Datum lt. Smarty: { $TIMESTAMP|date_format:'%d.%m.%Y' }
Datum eig. Funktion: { $TIMESTAMP|own_date_format:'d.m.Y' } |
Ausgabe:
Code: | Timestamp: -142477200
Datum lt. Smarty: 27.06.2004
Datum eig. Funktion: 27.06.1965 |
So funktioniert es wenigstens, dafür musst Du Dich halt an die Formatierungen der date-Funktion halten.
http://de.php.net/manual/de/function.date.php
Gruss,
Thorsten |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|