Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Probleme mit date_format

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Chrunchy
Smarty n00b


Joined: 20 Jun 2004
Posts: 1

PostPosted: Sun Jun 20, 2004 8:28 am    Post subject: Probleme mit date_format Reply with quote

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
View user's profile Send private message
noftinator
Smarty n00b


Joined: 26 Jun 2004
Posts: 3

PostPosted: Sun Jun 27, 2004 12:36 am    Post subject: Scheint ein PHP-Problem zu sein Reply with quote

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 Wink

[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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP