Michael
Michael

Reputation: 89

How to format a date string like '2018-08-31'

I've got a date-string like '2018-08-31' from tt_content and want to convert it like this: '31 August 2018' - how do I get this to work?

I've tried this:

10 = TEXT
10 {
    wrap = |
    data.field = tx_mask_cnt_news_item_date  // field in tt_content, is '2018-08-31'
    strftime = %e %B %Y
}

But this puts out the current date (in the desired format). Can somebody give me a hint?

Upvotes: 0

Views: 301

Answers (2)

Michael
Michael

Reputation: 89

I've found a solution: With strtotime = 1 the string will be converted into a timestamp and then strftime will work as expected:

10 = TEXT
10 {
    wrap = |
    field = tx_mask_cnt_news_item_date  // field in tt_content, is '2018-08-31'
    strtotime = 1
    strftime = %e %B %Y
}

Upvotes: 1

Rudy Gnodde
Rudy Gnodde

Reputation: 4565

Try this:

10 = TEXT
10 {
    wrap = |
    field = tx_mask_cnt_news_item_date
    strftime = %e %B %Y
}

data.field = tx_mask_cnt_news_item_date will set the content of tx_mask_cnt_news_item_date as the value for data, which will result in nothing. field directly in the TEXT object will set the content of tx_mask_cnt_news_item_date as the value of the TEXT object, which will then be passed through strftime.

Upvotes: 1

Related Questions