This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » format_date helper - ShortDatePattern Problem
format_date helper - ShortDatePattern Problem [message #20249] Tue, 23 January 2007 15:54 Go to next message
virtualize  is currently offline virtualize
Messages: 36
Registered: July 2006
Location: Zürich, Switzerland
Member
hi,

i'm trying to format a date with the format_date helper.
according to the docs ( http://www.symfony-project.com/book/trunk/templating_i18n_he lpers) the ShortDatePattern ('d') should give MM/dd/yyyy.
format_date($employee->getBirthDate(), 'd')

but i only get dates with a 2-digit year, like 23/01/07. how do i get the 4-digit year, like this 23/01/2007 ?

thanks in advance
christopher

Re: format_date helper - ShortDatePattern Problem [message #20306 is a reply to message #20249 ] Wed, 24 January 2007 10:28 Go to previous messageGo to next message
mikenolan  is currently offline mikenolan
Messages: 403
Registered: October 2006
Location: Lancashire, UK
Faithful Member
Which version of Symfony are you using? For me doing:
echo format_date('2007-01-26 01:02:03', 'd');


Outputs 2007-01-26.
Re: format_date helper - ShortDatePattern Problem [message #20318 is a reply to message #20306 ] Wed, 24 January 2007 13:06 Go to previous messageGo to next message
virtualize  is currently offline virtualize
Messages: 36
Registered: July 2006
Location: Zürich, Switzerland
Member
i'm using the latest beta, which is 1.0beta4.

echo format_date('2007-01-26 01:02:03', 'd');

returns '26.01.07' to my input field.

i use the format_helper in conjunction with i18n, so my current culture is set to de_CH (german/switzerland), if i switch to en_US i get '1/26/07' as expected but also with only 2-year digits.

thanks.
Re: format_date helper - ShortDatePattern Problem [message #20323 is a reply to message #20318 ] Wed, 24 January 2007 13:45 Go to previous messageGo to next message
mikenolan  is currently offline mikenolan
Messages: 403
Registered: October 2006
Location: Lancashire, UK
Faithful Member
echo format_date('2007-01-26 01:02:03', 'p', 'de_CH');


Gives me 26.01.2007.
Re: format_date helper - ShortDatePattern Problem [message #20335 is a reply to message #20323 ] Wed, 24 January 2007 15:09 Go to previous messageGo to next message
virtualize  is currently offline virtualize
Messages: 36
Registered: July 2006
Location: Zürich, Switzerland
Member
thanks mikenolan, where did you find that 'p' option? is this php specific or a symfony thing?
Re: format_date helper - ShortDatePattern Problem [message #20339 is a reply to message #20335 ] Wed, 24 January 2007 15:29 Go to previous messageGo to next message
mikenolan  is currently offline mikenolan
Messages: 403
Registered: October 2006
Location: Lancashire, UK
Faithful Member
It's a Symfony thing in sfDateFormat::getPattern().

    switch ($pattern)
    {
      case 'd':
        return $this->formatInfo->ShortDatePattern;
        break;
      case 'D':
        return $this->formatInfo->LongDatePattern;
        break;
      case 'p':
        return $this->formatInfo->MediumDatePattern;
        break;
      case 'P':
        return $this->formatInfo->FullDatePattern;
        break;        
      case 't':
        return $this->formatInfo->ShortTimePattern;
        break;
      case 'T':
        return $this->formatInfo->LongTimePattern;
        break;
      case 'q':
        return $this->formatInfo->MediumTimePattern;
        break;
      case 'Q':
        return $this->formatInfo->FullTimePattern;
        break;
      case 'f':
        return $this->formatInfo->formatDateTime($this->formatInfo->LongDatePattern, $this->formatInfo->ShortTimePattern);
        break;
      case 'F':
        return $this->formatInfo->formatDateTime($this->formatInfo->LongDatePattern, $this->formatInfo->LongTimePattern);
        break;
      case 'g':
        return $this->formatInfo->formatDateTime($this->formatInfo->ShortDatePattern, $this->formatInfo->ShortTimePattern);
        break;
      case 'G':
        return $this->formatInfo->formatDateTime($this->formatInfo->ShortDatePattern, $this->formatInfo->LongTimePattern);
        break;
      case 'i':
        return 'yyyy-MM-dd';
        break;
      case 'I':
        return 'yyyy-MM-dd HH:mm:ss';
        break;
      case 'M':
      case 'm':
        return 'MMMM dd';
        break;
      case 'R':
      case 'r':
        return 'EEE, dd MMM yyyy HH:mm:ss';
        break;
      case 's':
        return 'yyyy-MM-ddTHH:mm:ss';
        break;
      case 'u':
        return 'yyyy-MM-dd HH:mm:ss z';
        break;
      case 'U':
        return 'EEEE dd MMMM yyyy HH:mm:ss';
        break;
      case 'Y':
      case 'y':
        return 'yyyy MMMM';
        break;
      default :
        return $pattern;
    }


The top ones thing use your locale to determine the formatting.
<SOLVED!!> Re: format_date helper - ShortDatePattern Problem [message #67481 is a reply to message #20339 ] Thu, 11 December 2008 20:07 Go to previous messageGo to next message
carolina.boerr  is currently offline carolina.boerr
Messages: 4
Registered: November 2008
Junior Member
Seeking and looking I found the solution in
http://groups.google.com/group/symfony-es/browse_thread/thre ad/d95dbf5cb841f6db/93f8c1f73026665f?lnk=gst&q=formato+f echa+list#93f8c1f73026665f

Thanks a lot anyway!
----
Hi mikenolan:
I see that you've faced some problems with dates and maybe you can help me.

I'm using admin generator and i18n.
My default culture es en_US but I'm working with a user culture=es_AR

In the edit view, dates are shown correctly, with format dd/mm/yyyy but in my list view, they are shown in a strange format.

For example: edit-> 31/12/2008
is shown in list view as-> 2008/12/2031

My generator.yml is
  list:
    title: Listado
    display: [fecha_desde, fecha_hasta]
    actions:
      _create:
    object_actions:
      _edit:
      _delete:
    fields:
      fecha_desde: {params: date_format="p"}
      fecha_hasta: {params: date_format="p"}
        
  edit:
    title: Creación/Modificación
    display: [fecha_desde, fecha_hasta]
    fields:
      fecha_desde: {params: date_format="p"}
      fecha_hasta: {params: date_format="p"}


To set the user culture, I've changed actions.class.php of my module:
class LicenciasActions extends autoLicenciasActions
{

  public function executeList()
  {
  	$this->getUser()->setCulture('es_AR');
  	parent::executeList();
  }	
  
}


Have you had this problem at all?
Do you have any suggestion?

Thanks a lot in advance!
Carolina

[Updated on: Thu, 11 December 2008 20:35]

Re: <SOLVED!!> Re: format_date helper - ShortDatePattern Problem [message #72324 is a reply to message #67481 ] Fri, 13 February 2009 08:02 Go to previous message
manuelR
Messages: 1
Registered: February 2009
Location: Medellín, Colombia
Junior Member

I have the exact same problem Carolina. Is there anything on to this yet?
I saw in other post that using yy-MM-dd solves the problem but it doesnt. it just shortens some dates, but generally i keep getting the same weird year/date day: i.e February 2nd 2009 = 2002-02-2009

I've tried every single pattern anything on this?
Previous Topic:backend list-columns
Next Topic:[solved]how can I show single record without foreach ?
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software