0

How to get number of week for specific date in cakephp 3?

$this->mydate->i18nFormat('yyyy-MM-dd') will display year-month-date.

But what about string format for week number? Thanks.

Nurjan
  • 5,889
  • 5
  • 34
  • 54
Yosi Azwan
  • 497
  • 4
  • 15

1 Answers1

2

Have a closer look at the docs for Cake\I18n\Time::i18nFormat(), it tells you what you can pass as the format, and where to find a list of the accepted formatting patterns:

[...] You can either pass IntlDateFormatter constants as the first argument of this function, or pass a full ICU date formatting string as specified in the following resource: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax.

Cookbook > Date & Time > Formatting > Cake\I18n\Time::i18nFormat()

So long story short, the pattern letter for the week of the year is w, or ww if you want a leading zero, and for the week of the month it's W or WW.

ndm
  • 59,784
  • 9
  • 71
  • 110
  • Thanks :) your answer was very helpful. – Yosi Azwan Nov 09 '16 at 07:54
  • @ndm the icu-project.org link is dead (kinda), I found [unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details](https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details), but unsure if it can be a replacement – ᴍᴇʜᴏᴠ Sep 11 '20 at 03:51
  • 1
    @aexl They moved their docs. I've updated my answer with the new URL (the one you have there works too, it's simply the new API reference). I'll push a PR to update the CakePHP docs accordingly. – ndm Sep 11 '20 at 07:29