Symfony Helper -> format_date, how to use

It’s a Symfony thing in sfDateFormat::getPattern().

You can use this helper like this following example:

<?php echo format_date($blog_post->getCreatedAt(), "D“) ?>

The D is a pre-formatting from symfony, above a list about others pre formats options.

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;
    }

That’s really good to don’t lose time.

Respond to this post