Question T22665
Visible to All Users

date decreasing 1 day in display

created 7 days ago

Hi, I have a problem using SurveyJs, through the Designer tab. My recording json, in the date field (field in date format), saves the date in the database in the format YYYY/MM/DD, Example: 2025-10-29. When I use my other form, which has the function of loading and displaying this data from the database, for the user, it ends up SUBTRACTING, subtracting 1 day from the date, for example: 10/28/2025 (PT-BR format). If I leave it in the YYYY-MM-DD format it works correctly, but I need it to be in the PT-BR format (DD/MM/YYYY). I used the field in the date format and set the display format to date, but it subtracts 1 day from the date. If I disable the display format, it does not subtract, the date remains correct, but in the format that I cannot use, I need DD/MM/YYYY. Then I went for another approach, working with the date with a text field, and using a mask, to force the data to be saved in the database as DD/MM/YYYY, but the result is the same, it always ends up decreasing 1 day from the date. The question is, I need the date to be displayed to the user to be DD/MM/YYYY, but all the ways through surveyJS Designer (I can only do it through it), end up decreasing 1 day from the date. Can someone help me and explain why this happens? The database is SQL SERVER. The data is being saved correctly, the problem is in the display, when it is going to be shown to the user.

json recording

JSON
{ "pages": [ { "name": "page1", "elements": [ { "type": "panel", "name": "refracao", "questionTitleLocation": "top", "title": "Auto Refração", "showQuestionNumbers": "off", "elements": [ { "type": "text", "name": "DATE_LIBERACAO", "title": "Data de Liberação", "maskType": "datetime", "maskSettings": { "saveMaskedValue": true, "pattern": "dd/mm/yyyy" } }, { "type": "text", "name": "TIME_LIBERACAO", "minWidth": "150px", "startWithNewLine": false, "title": "Hora de Liberação", "inputType": "time" }, { "type": "text", "name": "VL_ARD_DP", "minWidth": "150px", "title": "DP" }, { "type": "html", "name": "question3", "minWidth": "150px", "html": "<strong>Auto Refração Dinâmica</strong>\n" }, { "type": "boolean", "name": "IE_RECEITA_DINAMICA", "minWidth": "150px", "startWithNewLine": false, "title": { "default": " ", "pt-br": "Receita" }, "titleLocation": "left", "defaultValueExpression": "false", "labelTrue": { "pt-br": "Sim" }, "labelFalse": { "pt-br": "Não" }, "valueTrue": "Sim", "valueFalse": "Não" }, { "type": "html", "name": "question7", "minWidth": "80px", "html": "<p class='titFormReceitaOculos'><strong>OD</strong></p>" }, { "type": "text", "name": "VL_OD_ARD_ESF", "minWidth": "150px", "title": "DE:" }, { "type": "text", "name": "VL_OD_ARD_CIL", "minWidth": "150px", "startWithNewLine": false, "title": "DC:" }, { "type": "text", "name": "VL_OD_ARD_EIXO", "minWidth": "150px", "startWithNewLine": false, "title": "Eixo:" }, { "type": "text", "name": "VL_OD_ARD_AV_SC", "minWidth": "150px", "startWithNewLine": false, "title": "Reflexo OD:" }, { "type": "html", "name": "question8", "minWidth": "80px", "html": "<p class='titFormReceitaOculos'><strong>OE</strong></p>" }, { "type": "text", "name": "VL_OE_ARD_ESF", "minWidth": "150px", "title": "DE:", "titleLocation": "top" }, { "type": "text", "name": "VL_OE_ARD_CIL", "minWidth": "150px", "startWithNewLine": false, "title": "DC:", "titleLocation": "top" }, { "type": "text", "name": "VL_OE_ARD_EIXO", "minWidth": "150px", "startWithNewLine": false, "title": "Eixo:", "titleLocation": "top" }, { "type": "text", "name": "VL_OE_ARD_AV_SC", "minWidth": "150px", "startWithNewLine": false, "title": "Reflexo OE:", "titleLocation": "top" }, { "type": "html", "name": "question4", "minWidth": "150px", "html": "<strong>Auto Refração Estática</strong>" }, { "type": "boolean", "name": "IE_RECEITA_ESTATICA", "minWidth": "150px", "startWithNewLine": false, "title": { "default": "\n", "pt-br": "Receita" }, "titleLocation": "left", "defaultValueExpression": "false\n", "labelTrue": { "pt-br": "Sim" }, "labelFalse": { "pt-br": "Não" }, "valueTrue": "Sim", "valueFalse": "Não" }, { "type": "html", "name": "question5", "html": "<strong>OD</strong>\n" }, { "type": "text", "name": "VL_OD_ARE_ESF", "minWidth": "150px", "title": "DE:" }, { "type": "text", "name": "VL_OD_ARE_CIL", "minWidth": "150px", "startWithNewLine": false, "title": "DC:" }, { "type": "text", "name": "VL_OD_ARE_EIXO", "minWidth": "150px", "startWithNewLine": false, "title": "Eixo:" }, { "type": "text", "name": "VL_OD_ARE_AV_SC", "minWidth": "150px", "startWithNewLine": false, "title": "Reflexo OD:" }, { "type": "html", "name": "question6", "html": "<strong>OE</strong>\n" }, { "type": "text", "name": "VL_OE_ARE_ESF", "minWidth": "150px", "title": "DE:" }, { "type": "text", "name": "VL_OE_ARE_CIL", "minWidth": "150px", "startWithNewLine": false, "title": "DC:" }, { "type": "text", "name": "VL_OE_ARE_EIXO", "minWidth": "150px", "startWithNewLine": false, "title": "Eixo:" }, { "type": "text", "name": "VL_OE_ARE_AV_SC", "minWidth": "150px", "startWithNewLine": false, "title": "Reflexo OE:" }, { "type": "comment", "name": "DS_OBSERVACAO", "title": "Observação:" }, { "type": "boolean", "name": "IE_SITUACAO", "title": { "default": " ", "pt-br": "Ativo" }, "titleLocation": "left", "defaultValueExpression": "false\n", "labelTrue": { "pt-br": "Sim" }, "labelFalse": { "pt-br": "Não" }, "valueTrue": "Sim", "valueFalse": "Não" } ] } ] } ] }

reading json

JSON
{ "locale": "pt-br", "pages": [ { "name": "page1", "elements": [ { "type": "panel", "name": "refracao", "questionTitleLocation": "top", "title": "Auto Refração", "showQuestionNumbers": "off", "elements": [ { "type": "expression", "name": "DATE_LIBERACAO", "minWidth": "150px", "title": { "pt-br": "Data de Liberação" } }, { "type": "expression", "name": "TIME_LIBERACAO", "minWidth": "150px", "startWithNewLine": false, "title": { "pt-br": "Hora de Liberação" } }, { "type": "expression", "name": "VL_ARD_DP", "minWidth": "150px", "title": "DP" }, { "type": "html", "name": "question3", "minWidth": "150px", "html": "<strong>Auto Refração Dinâmica</strong>\n" }, { "type": "expression", "name": "IE_RECEITA_DINAMICA", "minWidth": "150px", "startWithNewLine": false, "title": { "default": "\n", "pt-br": "Receita" }, "titleLocation": "left" }, { "type": "html", "name": "question7", "minWidth": "80px", "html": "<p class='titFormReceitaOculos'><strong>OD</strong></p>" }, { "type": "expression", "name": "VL_OD_ARD_ESF", "minWidth": "150px", "title": "DE:" }, { "type": "expression", "name": "VL_OD_ARD_CIL", "minWidth": "150px", "startWithNewLine": false, "title": "DC:" }, { "type": "expression", "name": "VL_OD_ARD_EIXO", "minWidth": "150px", "startWithNewLine": false, "title": "Eixo:" }, { "type": "expression", "name": "VL_OD_ARD_AV_SC", "minWidth": "150px", "startWithNewLine": false, "title": "Reflexo OD:" }, { "type": "html", "name": "question8", "minWidth": "80px", "html": "<p class='titFormReceitaOculos'><strong>OE</strong></p>" }, { "type": "expression", "name": "VL_OE_ARD_ESF", "minWidth": "150px", "title": "DE:", "titleLocation": "top" }, { "type": "expression", "name": "VL_OE_ARD_CIL", "minWidth": "150px", "startWithNewLine": false, "title": "DC:", "titleLocation": "top" }, { "type": "expression", "name": "VL_OE_ARD_EIXO", "minWidth": "150px", "startWithNewLine": false, "title": "Eixo:", "titleLocation": "top" }, { "type": "expression", "name": "VL_OE_ARD_AV_SC", "minWidth": "150px", "startWithNewLine": false, "title": "Reflexo OE:", "titleLocation": "top" }, { "type": "html", "name": "question4", "minWidth": "150px", "html": "<strong>Auto Refração Estática</strong>" }, { "type": "expression", "name": "IE_RECEITA_ESTATICA", "minWidth": "150px", "startWithNewLine": false, "title": { "default": "\n", "pt-br": "Receita" }, "titleLocation": "left" }, { "type": "html", "name": "question5", "html": "<strong>OD</strong>\n" }, { "type": "expression", "name": "VL_OD_ARE_ESF", "minWidth": "150px", "title": "DE:" }, { "type": "expression", "name": "VL_OD_ARE_CIL", "minWidth": "150px", "startWithNewLine": false, "title": "DC:" }, { "type": "expression", "name": "VL_OD_ARE_EIXO", "minWidth": "150px", "startWithNewLine": false, "title": "Eixo:" }, { "type": "expression", "name": "VL_OD_ARE_AV_SC", "minWidth": "150px", "startWithNewLine": false, "title": "Reflexo OD:" }, { "type": "html", "name": "question6", "html": "<strong>OE</strong>\n" }, { "type": "expression", "name": "VL_OE_ARE_ESF", "minWidth": "150px", "title": "DE:" }, { "type": "expression", "name": "VL_OE_ARE_CIL", "minWidth": "150px", "startWithNewLine": false, "title": "DC:" }, { "type": "expression", "name": "VL_OE_ARE_EIXO", "minWidth": "150px", "startWithNewLine": false, "title": "Eixo:" }, { "type": "expression", "name": "VL_OE_ARE_AV_SC", "minWidth": "150px", "startWithNewLine": false, "title": "Reflexo OE:" }, { "type": "expression", "name": "DS_OBSERVACAO", "title": "Observação:" }, { "type": "expression", "name": "IE_SITUACAO", "title": { "default": " ", "pt-br": "Ativo" }, "titleLocation": "left" } ] } ] } ] }
Show previous comments (2)
MS MS
michael santos 6 days ago

    Hello Jane,
    I also noticed that if I apply the mask to the form that sends the data, before the data enters the database, it already decreases the date by 1 day, thus storing the date in the wrong value. In other words, if I apply some formatter, mask for text field, the data is SENT with 1 day less, if I use the display format to read the data in dd/mm/yyyy, it displays with 1 day less. But if I remove everything, leaving the natural data, it sends and displays correctly, but with the yyyy/mm/dd mask. Masks for text field remove 1 day, displayformat displays with -1 day. Without masks and display format it works, but in the formatting that does not suit me. Is there any other alternative that I can use to display dd/mm/yyyy?

      Hello Michael,
      Thank you for the update. I may need additional time to reply. Please stay tuned.

        Hello Michael,
        Thank your patience. Before you send a date value to your database, it's required to convert it to a UTC value. When you load dates from your database, it's necessary to convert them to local dates. This way you can ensure that a correct fate is always restored.

        Regarding your additional comment:

        before the data enters the database, it already decreases the date by 1 day, thus storing the date in the wrong value.

        I would appreciate it if you could share a demo which reproduces this issue. In particular, I need to see how exactly you obtain a date value which is different from the value specified in your form.

        I look forward to your reply.

        Answers

        created 2 days ago

        Hello Jane.
        I managed to solve my problem. I'll leave my solution here, which helped me solve it, in case anyone else needs something similar. I kept my DATE_LIBERACAO field as a DATE type field, saving the information in the database as YYYY-MM-DD, for example, 2025-12-31. Now in my form that will load and display the information to the user, the form focused on read-only expression, I kept the field that displays as read-only expression, and in the Logic tab, I created a logic, that when the field is not empty, I would assemble the date in the format that I want, using substring and concatenation. This solved my problem. I'll leave pictures exemplifying what I did and the result.

        I've attached the photos showing the result achieved, how I did it, the information stored in the database, and the logic I used. Anyway, this solved my problem, and the date is not being decreased by 1 day.