> For the complete documentation index, see [llms.txt](https://manual.senseforce.io/manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.senseforce.io/manual/sf-platform/script-editor/working-with-timestamps/working-with-timestamps-in-r.md).

# Working with Timestamps in R

The SF timestamp is formatted as UNIX timestamp with millisecond precision. For our R scripting engine, this looks like an ordinary numeric. To create a date object, use the following snippet:

```
as.POSIXct(timestamp/1000, origin = "1970-01-01", tz="Europe/Vienna")
```

To use a R date object outside of a script, define a script result variable with data type either "timestamp" or "string". Using "string" has the advantage of formatting the date-time object as you like but when using a timestamp the widget will adjust the representation to the displayed time frame. Use the following code snippets to correctly format the date-objects to meet the correct output format requirements:

String as output,

```
outputStringTimestamp = as.character(internalDateObject)
```

Timestamp as output,

```
outputTimestamp = as.numeric(internalDateObject) * 1000
```

Alternatively look at the [lubridate](https://www.rdocumentation.org/packages/lubridate/versions/1.7.4) package. It offers many functions for handling timestamps and datetime objects in very intuitive way, just remember that lubridate is also expecting a timestamp in seconds and not in milliseconds, so devide the timestamp you get from your data by 1000.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://manual.senseforce.io/manual/sf-platform/script-editor/working-with-timestamps/working-with-timestamps-in-r.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
