Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
12 replies
Subscribers
8 subscribers
Views
7839 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
General
Covert Time to UNIX Time
sahilb
over 8 years ago
I want to convert the time into UNIX Timestamp. Is it is possible in Appian to convert a time into UNIX Timestamp format?
Thanks in Advance
OriginalPostID-239475
Discussion posts and replies are publicly visible
Top Replies
chetany
over 8 years ago
+1
A Score Level 1
Here is a Expression rule that you may use to convert time to a UNIX timestamp. It makes use of the fact that the difference between two datetimes is an interval. I have used it to convert the current…
0
Eduardo Fuentes
Appian Employee
over 8 years ago
Can you provide an example to make sure I suggest something that suits your requirement ? Is it really a long out of the date and time what you want to generate?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sahilb
over 8 years ago
I want to convert the Appian current timestamp into THE UTC format (Current Unix Timestamp).
e.g: 10/08/2016 @ 6:43am (UTC) is equivalent to: "1475909014". I want "1475909014" as an output
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 8 years ago
I went through the functions documentation
forum.appian.com/.../Appian_Functions.html
and didn't find a way to convert to a timestamp.
Maybe building a custom function that takes a date and time and returns the time stamp. Basically if you code your custom function to return a long, and you just simply return the date and time you're passing, since the product maps it to java.sql.Timestamp I think you'll get exactly what you need.
Example
@Function
public Long getLocalTime(ServiceContext sc, @Parameter Timestamp datetime) {
return datetime;
}
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 8 years ago
Here is a Expression rule that you may use to convert time to a UNIX timestamp. It makes use of the fact that the difference between two datetimes is an interval. I have used it to convert the current datetime (now()) to UNIX timestamp
with(
local!unixEpoch : fn!datetime(1970, 1, 1, 0,0,0,0),
local!intervalDiff: fn!now() - local!unixEpoch,
local!stringintervalDiff: fn!tostring(local!intervalDiff),
local!days: fn!tointeger(local!intervalDiff),
local!stringPartExcludingDays: fn!split(local!stringintervalDiff, "::")[2],
local!splitPartExcludingDays: fn!split(local!stringPartExcludingDays, ":"),
local!hours: fn!tointeger(local!splitPartExcludingDays[1]),
local!minutes: fn!tointeger(local!splitPartExcludingDays[2]),
local!seconds: fn!tointeger(local!splitPartExcludingDays[3]),
local!days*24*3600 + local!hours*3600 + local!minutes*60 + local!seconds
)
Cancel
Vote Up
+1
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 8 years ago
Please create a rule input and use it instead of fn!now() in the above expression. It will give you the expected output for the sample input you have mentioned.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sahilb
over 8 years ago
Thanks chetany. It is working properly.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 8 years ago
And here's a suggestion from someone to do it the other way around
forum.appian.com/.../f-159035
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 8 years ago
@Eduardo, thanks for sharing. It can be useful to know how to do it the other way.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 8 years ago
Another option:
forum.appian.com/.../summary
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 8 years ago
Although that plug-in only works if what you want to convert to the timestamp is "now()". Just thought it'd make sense to mention it.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
>