or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

core-data-structures.mddata-manipulation.mdexpression-system.mdfile-io.mdindex.mdmathematical-functions.mdreductions-aggregations.mdrow-operations.mdset-operations.mdstring-operations.mdtime-operations.mdtype-system.md

time-operations.mddocs/

0

# Time Operations

1

2

Date and time manipulation functions for temporal data analysis and time series operations.

3

4

## Capabilities

5

6

### Time Component Extraction

7

8

```python { .api }

9

def time.year(x):

10

"""Extract year component from datetime"""

11

12

def time.month(x):

13

"""Extract month component from datetime"""

14

15

def time.day(x):

16

"""Extract day component from datetime"""

17

18

def time.hour(x):

19

"""Extract hour component from datetime"""

20

21

def time.minute(x):

22

"""Extract minute component from datetime"""

23

24

def time.second(x):

25

"""Extract second component from datetime"""

26

27

def time.nanosecond(x):

28

"""Extract nanosecond component from datetime"""

29

30

def time.day_of_week(x):

31

"""Extract day of week (0=Monday, 6=Sunday)"""

32

```

33

34

### Date/Time Construction

35

36

```python { .api }

37

def time.ymd(year, month, day):

38

"""

39

Create date from year, month, day components.

40

41

Parameters:

42

- year: Year values

43

- month: Month values (1-12)

44

- day: Day values (1-31)

45

46

Returns:

47

Date column

48

"""

49

50

def time.ymdt(year, month, day, hour=0, minute=0, second=0):

51

"""

52

Create datetime from components.

53

54

Parameters:

55

- year: Year values

56

- month: Month values (1-12)

57

- day: Day values (1-31)

58

- hour: Hour values (0-23, default 0)

59

- minute: Minute values (0-59, default 0)

60

- second: Second values (0-59, default 0)

61

62

Returns:

63

Datetime column

64

"""

65

```

66

67

## Examples

68

69

```python

70

import datatable as dt

71

72

# Create datetime data

73

DT = dt.Frame({

74

'datetime_str': ['2023-01-15 14:30:45', '2023-06-22 09:15:30', '2023-12-31 23:59:59']

75

})

76

77

# Convert to datetime and extract components

78

result = DT[:, dt.update(

79

datetime_val=dt.as_type(f.datetime_str, dt.time64),

80

year=dt.time.year(dt.as_type(f.datetime_str, dt.time64)),

81

month=dt.time.month(dt.as_type(f.datetime_str, dt.time64)),

82

day=dt.time.day(dt.as_type(f.datetime_str, dt.time64)),

83

hour=dt.time.hour(dt.as_type(f.datetime_str, dt.time64)),

84

minute=dt.time.minute(dt.as_type(f.datetime_str, dt.time64)),

85

day_of_week=dt.time.day_of_week(dt.as_type(f.datetime_str, dt.time64))

86

)]

87

88

# Construct dates from components

89

dates = dt.Frame({

90

'year': [2023, 2023, 2023],

91

'month': [1, 6, 12],

92

'day': [15, 22, 31]

93

})

94

95

dates_result = dates[:, dt.update(

96

date_val=dt.time.ymd(f.year, f.month, f.day),

97

datetime_val=dt.time.ymdt(f.year, f.month, f.day, 12, 0, 0)

98

)]

99

```