Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I remove specific elements from a TimeStamp?

Asked by
Rukreep 15
3 years ago

For example, I have this date right here. (2009-02-24T15:37:37.58Z) and I want to remove specific elements to just display the year, month and day. So it would look like this. (2009-02-24)

How can I archieve something like this using Lua?

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Generally, you can use gsub which can replace a pattern in the string with a desired character(s), which we can use empty strings for to remove specific elements. In this case, we can just search for a substring matching a "T" and everything else that follows it and replace it with an empty string. In layman's terms, it will remove the character "T" and everything else that follows it so you're just left with the date.

timestamp = timestamp:gsub("T.*", "")
Ad

Answer this question