> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createtimespan.md).

# CreateTimeSpan

Creates a timespan {@link java.time.Duration}

## Method Signature

```
CreateTimeSpan(days=[numeric], hours=[numeric], minutes=[numeric], seconds=[numeric], milliseconds=[numeric])
```

### Arguments

| Argument       | Type      | Required | Description                                | Default |
| -------------- | --------- | -------- | ------------------------------------------ | ------- |
| `days`         | `numeric` | `true`   | The number of days in the timespan         |         |
| `hours`        | `numeric` | `true`   | The number of hours in the timespan        |         |
| `minutes`      | `numeric` | `true`   | The number of minutes in the timespan      |         |
| `seconds`      | `numeric` | `true`   | The number of seconds in the timespan      |         |
| `milliseconds` | `numeric` | `false`  | The number of milliseconds in the timespan | `0`     |

## Examples

### Use of createTimespan in a bx:query

The createTimespan function is useful in the cachedwithin attribute of bx:query.

```java
<bx:query name="GetParks" datasource="cfdocexamples" cachedWithin="#createTimespan( 0, 6, 0, 0 )#"> 
 SELECT PARKNAME, REGION, STATE 
 FROM Parks 
 ORDER by ParkName, State 
 </bx:query>
```

### The createTimespan function returns a numeric value

Passing 6 hours, or a quarter of a day returns a double representing 1/4

[Run Example](https://try.boxlang.io/?code=eJxLLkpNLEkNycxNLS5IzNNQMNBRMNMBkQYKmtZcAJu1CDY%3D)

```java
createTimespan( 0, 6, 0, 0 );

```

Result: PT6H

### Adding a date and a timestamp

Instead of using dateAdd you could add a timestamp to a date object

```java
dateFormat( createDate( 2017, 1, 1 ) + createTimespan( 2, 0, 0, 0 ) );

```

Result: 03-Jan-17

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxLKc0t0FBILkpNLEkNycxNDS5IzNNQMNABIWMQpaCpoGnNpaCvD%2BTq5mbmlZakKpQAFRYDFXIBAD0DEdU%3D)

```java
dump( createTimeSpan( 0, 0, 30, 0 ) );
 // 30-minute timespan

```

## Related

* [ClearTimezone](/boxlang-language/reference/built-in-functions/temporal/cleartimezone.md)
* [CreateDate](/boxlang-language/reference/built-in-functions/temporal/createdate.md)
* [CreateDateTime](/boxlang-language/reference/built-in-functions/temporal/createdatetime.md)
* [CreateODBCDate](/boxlang-language/reference/built-in-functions/temporal/createodbcdate.md)
* [CreateODBCDateTime](/boxlang-language/reference/built-in-functions/temporal/createodbcdatetime.md)
* [CreateODBCTime](/boxlang-language/reference/built-in-functions/temporal/createodbctime.md)
* [CreateTime](/boxlang-language/reference/built-in-functions/temporal/createtime.md)
* [DateAdd](/boxlang-language/reference/built-in-functions/temporal/dateadd.md)
* [DateCompare](/boxlang-language/reference/built-in-functions/temporal/datecompare.md)
* [DateConvert](/boxlang-language/reference/built-in-functions/temporal/dateconvert.md)
* [DateDiff](/boxlang-language/reference/built-in-functions/temporal/datediff.md)
* [DateFormat](/boxlang-language/reference/built-in-functions/temporal/dateformat.md)
* [DatePart](/boxlang-language/reference/built-in-functions/temporal/datepart.md)
* [DateTimeFormat](/boxlang-language/reference/built-in-functions/temporal/datetimeformat.md)
* [Day](/boxlang-language/reference/built-in-functions/temporal/day.md)
* [DayOfWeek](/boxlang-language/reference/built-in-functions/temporal/dayofweek.md)
* [DayOfWeekAsString](/boxlang-language/reference/built-in-functions/temporal/dayofweekasstring.md)
* [DayOfWeekShortAsString](/boxlang-language/reference/built-in-functions/temporal/dayofweekshortasstring.md)
* [DayOfYear](/boxlang-language/reference/built-in-functions/temporal/dayofyear.md)
* [DaysInMonth](/boxlang-language/reference/built-in-functions/temporal/daysinmonth.md)
* [DaysInYear](/boxlang-language/reference/built-in-functions/temporal/daysinyear.md)
* [FirstDayOfMonth](/boxlang-language/reference/built-in-functions/temporal/firstdayofmonth.md)
* [GetNumericDate](/boxlang-language/reference/built-in-functions/temporal/getnumericdate.md)
* [GetTime](/boxlang-language/reference/built-in-functions/temporal/gettime.md)
* [GetTimezone](/boxlang-language/reference/built-in-functions/temporal/gettimezone.md)
* [GetTimezoneInfo](/boxlang-language/reference/built-in-functions/temporal/gettimezoneinfo.md)
* [Hour](/boxlang-language/reference/built-in-functions/temporal/hour.md)
* [Millisecond](/boxlang-language/reference/built-in-functions/temporal/millisecond.md)
* [Minute](/boxlang-language/reference/built-in-functions/temporal/minute.md)
* [Month](/boxlang-language/reference/built-in-functions/temporal/month.md)
* [MonthAsString](/boxlang-language/reference/built-in-functions/temporal/monthasstring.md)
* [MonthShortAsString](/boxlang-language/reference/built-in-functions/temporal/monthshortasstring.md)
* [Nanosecond](/boxlang-language/reference/built-in-functions/temporal/nanosecond.md)
* [Now](/boxlang-language/reference/built-in-functions/temporal/now.md)
* [Offset](/boxlang-language/reference/built-in-functions/temporal/offset.md)
* [ParseDateTime](/boxlang-language/reference/built-in-functions/temporal/parsedatetime.md)
* [Quarter](/boxlang-language/reference/built-in-functions/temporal/quarter.md)
* [Second](/boxlang-language/reference/built-in-functions/temporal/second.md)
* [SetTimezone](/boxlang-language/reference/built-in-functions/temporal/settimezone.md)
* [TimeFormat](/boxlang-language/reference/built-in-functions/temporal/timeformat.md)
* [TimeUnits](/boxlang-language/reference/built-in-functions/temporal/timeunits.md)
* [Week](/boxlang-language/reference/built-in-functions/temporal/week.md)
* [Year](/boxlang-language/reference/built-in-functions/temporal/year.md)


---

# 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:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createtimespan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
