Formatting Dates

david1pro Member
edited December 2022 in General support

I want to format dates in a couple of different ways, depending on where it is showing on my site. I know the default format can be set under Options>General>Date Format, but some of these don't work. For example, setting the style "02/25/2008" shows up as "minute#/25/2008" for every photo, no matter the month it was taken (IE: 0/22/2018). The same happens with style "02/25/18" - for the months - it's giving the minute, not the month.

Additionally, as I do want different styles in different places, I have been using: <?php echo printImageDate($before = '', $format = "ALL SORTS OF DIFFERENT THINGS HERE"); ?> But I can't figure out the month. The codes listed here: https://www.php.net/manual/en/function.date.php do not work correctly (this is the link from the Date Format description on the general options page). For example, the code "m.d.y" gives the month as the minute just as it does when selecting the universal date format under Options>General>Date Format.

Am I missing the true code for month (for both single and double digit, as in 1/25/2008 and 01/25/2008)? All my guesses have been wrong. If I try "n" (which should be the short version of the month, single digit for the first 9 months) it causes the whole date to fail. "m" seems to be minutes, not month, despite the lack of a nearby "h" for hours.

In addition to not getting the date codes to work, I can't get escapes to work either as exampled on the php site to format something like Wednesday the 15th, you would use<?php echo date('l \t\h\e jS'); ?>. (I get "Saturday \11 30" for what should say "Saturday the 3rd" (for a photo from 11/3/2018)

Any thoughts on what I am doing wrong?

Comments

  • acrylian Administrator, Developer

    Actually the codes on https://www.php.net/manual/de/datetime.format.php are the ones to use and we extensively tested that extenively. tions. It is really tricky as we have to do some internal conversions.

    Do you have the intl PHP extension available? That makes a difference to debug this as we have to date formatting internally.. In PHP 8.1 a few things changed internally since strftime() is deprecated. THe intl class uses different time codes so we have to do some internal conversion for locale aware formatting (translated month or day names).

  • fretzl Administrator, Developer
    edited December 2022

    We have extended the intl conversion array. Please try Zenphoto 1.6.1a (development)

  • Thanks very much. That fixes the month with both "m" for "07" (July) and "n" for just 7 (single-digit July).

    I still can't seem to get escaping to work, as in the <?php echo date('l \t\h\e jS'); ?> example above. Am I missing a procedure on how to correctly do that?

  • acrylian Administrator, Developer
    edited December 2022

    We will have to check. It might turn out that certain things are not possible due to the double conversion necessary. We internally don't and can't simply use date() for formatting. The PHP guys made things a lot more complicated… But we'll see.

    For now try a simpler formatting please.

Sign In or Register to comment.