- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
Enhanced Security Measures in Place: To ensure a safer experience, we’ve implemented additional, temporary security measures for all users.
08-17-2023 08:38 AM
I am trying to convert a string to a timestamp object and cannot understand how the parse_timestamp function works.
My string is as follow :
08-18-2023 09:22 AM
Hello @unlucky ,
Thanks for reaching out on LiveCommunity!
I think the function you are looking for is format_timestamp in place of format_string because your data is already in timestamp format.
Lets understand the definition of these 3 functions.
parse_timestamp() -> The parse_timestamp()
function returns a TIMESTAMP object after converting a string representation of a timestamp.
format_timestamp() -> The format_timestamp()
function returns a string after formatting a timestamp according to a specified string format.
format_string() -> The format_string()
function returns a string from a format string that contains zero or more format specifiers, along with a variable length list of additional arguments that matches the format specifiers.
Since the string you are trying to convert is already a timestamp hence please use format_timestamp function which will take a timestamp and return a string to parse_timestamp function to convert it to a timestamp of your choice. I have tried below line and its working for me.
alter time_test = parse_timestamp("%Y/%m/%d %H:%M:%S", format_timestamp("%Y/%m/%d %H:%M:%S", _time))
Below are the reference link for above functions.
08-18-2023 10:15 AM
ErrorField timestamp for function format_timestamp is invalid. Expected date but received string.
As I was saying, even though my string contains a timestamp, it is still a string!
Maybe there is something I am not understanding here, but what I am trying to achieve is to convert this string to a date type.
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!