#timestamp Handling

1 messages · Page 1 of 1 (latest)

torn pond
#

I have saved data from the Custom Model to mt DB using the following query

UPDATE signature
SET signature = {{Custom1.model.signature}},
    name = {{Custom1.model.printName}},
    timestamp =  CURRENT_TIMESTAMP,
        note = {{Custom1.model.note}}
WHERE id = {{contactQuery.data[0].id}}

The datatype of timestamp is TIMESTAMP

When I run a query to fetch the data, the query returns the saved timeStamp.

I then use a JS Script to format the timestamp to then enter back into a different custom Widget.
The JS output of the timestamp though is the current timestamp of when the JS was run, rather than the saved timestamp pulled by the query.

the section handling the timestamp

const formattedTimeStamp = moment(item.timeStamp).isValid() 
                    ? moment(item.timeStamp).format('YYYY-MM-DD HH:mm:ss') 
                    : 'N/A';

                console.log("Formatted timeStamp:", formattedTimeStamp);

Is there something I need to ammend in order to handle this correctly? I have tried multiple differnet variations and also got chatGPT involved but no joy

unborn oxideBOT
#

Hello! I'm Appy, your Appsmith support bot.

It seems like there might be an issue with how the timestamp data is being passed to your JavaScript function. The issue could be related to the case sensitivity or the exact property name used in your JavaScript code.

First, ensure that the property name timeStamp in item.timeStamp exactly matches the field name from your query result. Field names are case-sensitive. If the field name in your database or the query result is timestamp (all lowercase), you should use item.timestamp instead of item.timeStamp.

Here's the corrected version of your script if the issue is indeed a case sensitivity problem:

const formattedTimeStamp = moment(item.timestamp).isValid()
? moment(item.timestamp).format('YYYY-MM-DD HH:mm:ss')
: 'N/A';

console.log("Formatted timeStamp:", formattedTimeStamp);

Please check the exact field name in your query result and adjust the JavaScript code accordingly. If the problem persists, you might want to log the entire item object to ensure it contains the expected data:

console.log("Item data:", item);

This will help you verify that the timestamp data is being retrieved correctly from your query.

If you don't find my response helpful, you can request to speak to a human agent.

unborn oxideBOT
#

@torn pond Was the bot correct here about the syntax error?

torn pond
#

Yes lol
Chat gpt rewrote the code and for some reason changed it to timeStamp. I didn't notice and neither did chatgpt

unborn oxideBOT
#

I'm glad we identified the issue with the field name! If you have any more questions or need further assistance with your Appsmith application, feel free to ask. Happy coding!

If you don't find my response helpful, you can request to speak to a human agent.