Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Token value date format syntax

  • joeschwab
  • joeschwab's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 9 months ago #229119 by joeschwab
Token value date format syntax was created by joeschwab
Hello!
I am displaying the value of a token attribute as text in a survey question, where the attribute value is a timestamp. I would like to convert the format of the date, but i don't seem to have the syntax quite right.

To display the token value, I am using {TOKEN:ATTRIBUTE_4}, which displays the stored value. 

And to format the date, I have:
{date("F j, Y",strtotime(TOKEN:ATTRIBUTE_4))}

However this does not display anything. Any guidance would be greatly appreciated.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago - 1 year 9 months ago #229120 by Joffm
Replied by Joffm on topic Token value date format syntax
Hi,
you did not say how you set the attribute exactly
Only

where the attribute value is a timestamp

Is it really a unix timestamp, or?

To use your equation the attribute should have the "usual" MySQL format 'yyyy-mm-dd'
A quick test


 

If your attribute is a unix timestamp you must not use function "strtotime()". You already have the timestamp.
{date("F j, Y",1654120800)}

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 9 months ago by Joffm.

Please Log in to join the conversation.

  • joeschwab
  • joeschwab's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 9 months ago #229121 by joeschwab
Replied by joeschwab on topic Token value date format syntax
our date in the token attribute is formatted like: 2022-04-04 00:03:11

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #229123 by Joffm
Replied by Joffm on topic Token value date format syntax
I do not see any issue with
{date("F j, Y",strtotime(TOKEN:ATTRIBUTE_1))}

LimeSurvey Version 3.27.33.
 

LimeSurvey Version 5.3.17.
 

So there seems to be something else on your side.
Are there quotes around your attribute, or whatever?

And you forgot to answer the initial questions.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • joeschwab
  • joeschwab's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 9 months ago - 1 year 9 months ago #229164 by joeschwab
Replied by joeschwab on topic Token value date format syntax
Hey Joffm,
the date is inserted as a token attribute using the limesurvey api, the resulting value looks like:

2022-25-03 18:47

I do not have any quotes around the attribute. here is a screen capture of my question source:

How stressed have you been by the pandemic, in the <strong>past 2 months</strong>, since {date("F j, Y",strtotime(TOKEN:ATTRIBUTE_4))}?

displays like:

How stressed have you been by the pandemic, in the past 2 months, since?

The value will display if i use {TOKEN:ATTRIBUTE_4}, just not with the date function formatting.

Limesurvey Version : Version 3.18.0+190923

I also tested on the free hosted limesurvey account at ciphr.limesurvey.net running  Version 5.3.17 , and it also does not display. I must be missing something in the syntax
 
Last edit: 1 year 9 months ago by joeschwab.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #229165 by Joffm
Replied by Joffm on topic Token value date format syntax
Well, the quotes were just an example. There may be other things.
Start at the beginning:
Display 
#{TOKEN: ATTRIBUTE_4}#

{strtotime(TOKEN: ATTRIBUTE_4)}

As you need only the date{strtotime(substr(TOKEN: ATTRIBUTE_4,0,10))}

What happens if you enter this date in a question of type "short text" Q1 and enter Q1 in your date-function?

Meaning, first make sure that all parts of the function are fine.

I hope it was a typo.
2022-25-03 is not a valid date.

Joffm


​​​​​

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • joeschwab
  • joeschwab's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 9 months ago #229166 by joeschwab
Replied by joeschwab on topic Token value date format syntax
Wow. I feel really stupid!
I had the month and date reversed in my date format! after correcting the date format, its working now.
thank you!

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose