> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# ToTime()

## Definition

Calculates an integer value representing a time.

Integer representation of time is in the format Hmmss where 7:30 AM would be 73000 and 2:15:12 PM would be 141512.

## Method Return Value

An **int** value representing a time structure.

## Syntax

`ToTime(DateTime time)`

`ToTime(int hour, int minute, int second)`

## Parameters

| Parameter  | Description                                                                                                                               |
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| **time**   | A DateTime structure to calculate. Note: See also the [Time](/developer/desktop-sdk/references/common/iseriest/timeseries/time) property. |
| **hour**   | An **int** value representing the hour used for the input.                                                                                |
| **minute** | An **int** value representing the minute used for the input.                                                                              |
| **second** | An **int** value representing the second used for the input.                                                                              |

NinjaScript uses the .NET DateTime structure which can be complicated for novice programmers. If you are familiar with **C#** you can directly use DateTime structure properties and methods for date and time comparisons; otherwise, use this method and the [ToDay()](/developer/desktop-sdk/references/common/analytical/today) method.

## Examples

```csharp
// Only trade between 7:45 AM and 1:45 PM
if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
{
    // Strategy logic goes here
}
```

```csharp
// Store start time as an int variable to be compared
int startTime = ToTime(9, 30, 00); // 93000

// Only trade after 9:30 AM
if (ToTime(Time[0]) >= startTime)
{
    // Strategy logic goes here
}
```