lisardo
lisardo

Reputation: 1454

format date in typoscript in TYPO3 8

I want to format the date with typoscript:

10 = CONTENT
10 {
    table = tx_beratungstermine_domain_model_termine
    select.pidInList = 456
    renderObj = COA
    renderObj {
        10 = TEXT
        10.field = datetime
        10.strftime = %A den %d.%m.%Y

        20 = TEXT
        20.value = |

        30 = TEXT
        30.field = uid

        stdWrap.wrap = |[\n]
    }
}

It should work but i get

Donnerstag den 01.01.1970

Without the line

10.strftime = %A den %d.%m.%Y

I get the correct date but in false format.

What is wrong with my code?

Thank!

Upvotes: 0

Views: 1110

Answers (2)

mallo
mallo

Reputation: 96

For others coming around who don't want to change the database structure:

10 = TEXT
10 {
  field = datetime
  strtotime = 1
  strftime = %d.%m.%Y
}

The string value of the datetime field is first converted to a UNIX timestamp by strtotime and then formatted by strftime.

Upvotes: 1

lisardo
lisardo

Reputation: 1454

OK, I found the reason. The problem was the definition of the datetime field in the database. typoscript date does not work with a sql field of type datetime. It only works with field type int. I had to change the sql to:

datetime int(11) DEFAULT '0' NOT NULL,

and the TCA to

'config' => [
    'type' => 'input',
    'size' => 16,
    'eval' => 'datetime',
    ],
],

Upvotes: 2

Related Questions