List Info

Thread: date formatting




date formatting
user name
2007-10-04 07:59:08
hello,

in my template I have an input field which contains the date
a shelf 
expires.

<input type="text"
name="{$shelf_expire.name}" 
value="{$shelf_expire_value}"
class="bg{$shelf_expire.farbe}" 
size="{$shelf_expire.breite}"
{$shelf_expire.readstatus} />

Given the value for $shelf_expire_value is 2099-12-31 the
template 
returns just that.


If I use:
value="{$shelf_expire_value|date_format:'%d.%m.%Y'}&quo
t; instead of 
value="{$shelf_expire_value}" I get the result:
04.10.2007, which is 
today's date...

Is date_format only working with a certain type (format) of
string? How 
can I get the desired output of: 31.12.2099?

Thanks in advance,
Peggy

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


Re: date formatting
user name
2007-10-04 08:06:24
hello,

> hello,
>
> in my template I have an input field which contains the
date a shelf
> expires.
>
> Given the value for $shelf_expire_value is 2099-12-31
the template
> returns just that.
>
> If I use:
>
value="{$shelf_expire_value|date_format:'%d.%m.%Y'}&quo
t; instead of
> value="{$shelf_expire_value}" I get the
result: 04.10.2007, which is
> today's date...
>
> Is date_format only working with a certain type
(format) of string? How
> can I get the desired output of: 31.12.2099?

The documentation says: "Dates can be passed to Smarty
as unix timestamps,
mysql timestamps or any string made up of month day year,
parsable by
php's strtotime()."
The strtotime function accepts only english dates.
31.12.2099 is not an
english date!!
Take a look here : <http://fr3.php.net/manual/en/function.strtotime.php>

Regards,
Vincent

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


Re: date formatting
user name
2007-10-04 09:11:57
On Thu, Oct 04, 2007 at 03:06:24PM +0200, Vincent DEBOUT
wrote:
> hello,
> 
> > hello,
> >
> > in my template I have an input field which
contains the date a shelf
> > expires.
> >
> > Given the value for $shelf_expire_value is
2099-12-31 the template
> > returns just that.
> >
> > If I use:
> >
value="{$shelf_expire_value|date_format:'%d.%m.%Y'}&quo
t; instead of
> > value="{$shelf_expire_value}" I get the
result: 04.10.2007, which is
> > today's date...
> >
> > Is date_format only working with a certain type
(format) of string? How
> > can I get the desired output of: 31.12.2099?
> 
> The documentation says: "Dates can be passed to
Smarty as unix timestamps,
> mysql timestamps or any string made up of month day
year, parsable by
> php's strtotime()."
> The strtotime function accepts only english dates.
31.12.2099 is not an
> english date!!
> Take a look here : <http://fr3.php.net/manual/en/function.strtotime.php>

No, Peggy does not pass DD.MM.YYYY, she passes YYYY-MM-DD,
which is
fine for strtotime() and wants DD.MM.YYYY as output. The
problem is,
that the range strftime() (and strtotime()) can handle is
limited by
the underlying operating system. My system for example will
only
handle dates correctly up to january 2038.
 
> Regards,
> Vincent

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


Re: date formatting
user name
2007-10-04 09:28:29
Thanks to you both!

I just figured out the problem when reading the doc
provided:

(docs) Note:  The valid range of a timestamp is typically
from Fri, 13 
Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.
(These are the 
dates that correspond to the minimum and maximum values for
a 32-bit 
signed integer.)

Hmmm... I gues I have to do some stringformatting instead.

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


Re: date formatting
user name
2007-10-04 09:30:42
Thanks to both of you!

I just figured out the problem (as messju statet) when
reading in the 
docs provided:

Note:  The valid range of a timestamp is typically from Fri,
13 Dec 1901 
20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are
the dates that 
correspond to the minimum and maximum values for a 32-bit
signed integer.)

Hmmm... I guess, I have to do some string formatting
instead.

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


Re: date formatting
user name
2007-10-04 11:03:18
Peggy Schatz wrote:
> Thanks to both of you!
>
> I just figured out the problem (as messju statet) when
reading in the 
> docs provided:
>
> Note:  The valid range of a timestamp is typically from
Fri, 13 Dec 
> 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.
(These are the 
> dates that correspond to the minimum and maximum values
for a 32-bit 
> signed integer.)
>
> Hmmm... I guess, I have to do some string formatting
instead.
>
Another option is to override the built-in date_format
function with 
your own plugin that has more robust date handling such as
PEAR:ate.  
To override built-in plugins, you can add an entry to the
beginning of 
the plugins_dir array:

$tpl = new Smarty();
array_unshift($tpl->plugins_dir, '/my/plugins/dir/');

- Ken Snyder

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


Re: date formatting
user name
2007-10-05 02:57:11
Yes, I used a simple plugin of my own:


function smarty_modifier_mydate_format($date_in,$lang)
{
if($date_in != "") {
	$temp = explode("-",$date_in);
	if($lang == "german") {
		$date_out = $temp[2]. "." . $temp[1] .
"." .$temp[0];
		}
	else {
		$date_out = $temp[1]. "/" . $temp[2] .
"/" .$temp[0];
		}
	return $date_out;
	}
}

I'll take a look at PEAR:ate too,
since PEAR is implemented anyway. 
Thanks!

Ciao,
Peggy


> Another option is to override the built-in date_format
function with 
> your own plugin that has more robust date handling such
as PEAR:ate.  
> To override built-in plugins, you can add an entry to
the beginning of 
> the plugins_dir array:
> 
> $tpl = new Smarty();
> array_unshift($tpl->plugins_dir,
'/my/plugins/dir/');
> 
> - Ken Snyder

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


[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )