Date Formatting w/ PHP
  • I'm trying to display a formatted date stored in a Vae structure using PHP. I'm starting with this:
    <?php foreach (vae("/partners[name='Discovery']") as $partner) {echo $partner->delivery_date;} ?>
    That returns a string like 1290488400, but I need to return a string like November 24, 2010. Any Ideas?

    I tried using this but it doesn't render anything:
    echo(date('F d, Y', $partner->delivery_date));

  • 2 Answers sorted by
  • This made it work:

    echo(date('F d, Y', "$partner->delivery_date"));

  • Bingo. This is an extremely frustrating part of using PHP with Vae.

    PHP does not currently support implicit casting of an object to an integer, and Vae's values are represented as objects.

    So the takeaway is that whenever you're trying to pass a Vae value into a function that expects an Integer value, you need to either put an explicit (string) cast in front of it or do what you did with the quotes.

    We've tried to come up with a better solution for this, but short of patching PHP pretty heavily, it doesn't seem possible yet. Hopefully PHP 6 will address this problem.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion