danfo.toDateTime
Converts an array of Date strings to Date object.
danfo.toDateTime(data)
Parameters
Type
Description
Default
data
Array, Series
data: Array
Series with Date strings to convert to Date time.

Examples

In the following example, we convert a Series of Date strings to DateTime objects, so we can call various Date methods on them.
Node
Browser
1
const dfd = require('danfojs-node')
2
3
let data = new dateRange({ "start": '1/1/2018', period: 12, freq: 'M' })
4
let sf = new Series(data)
5
sf.print()
6
7
let dt = toDateTime(data)
8
dt.dayOfMonth().print()
9
dt.dayOfWeekName().print()
10
dt.hours().print()
Copied!
1
Copied!
Output
1
╔═══╤════════════════════════╗
2
║ 0 │ 1/1/2018, 12:00:00 AM ║
3
╟───┼────────────────────────╢
4
║ 1 │ 2/1/2018, 12:00:00 AM ║
5
╟───┼────────────────────────╢
6
║ 2 │ 3/1/2018, 12:00:00 AM ║
7
╟───┼────────────────────────╢
8
║ 3 │ 4/1/2018, 12:00:00 AM ║
9
╟───┼────────────────────────╢
10
║ 4 │ 5/1/2018, 12:00:00 AM ║
11
╟───┼────────────────────────╢
12
║ 5 │ 6/1/2018, 12:00:00 AM ║
13
╟───┼────────────────────────╢
14
║ 6 │ 7/1/2018, 12:00:00 AM ║
15
╟───┼────────────────────────╢
16
║ 7 │ 8/1/2018, 12:00:00 AM ║
17
╟───┼────────────────────────╢
18
║ 8 │ 9/1/2018, 12:00:00 AM ║
19
╟───┼────────────────────────╢
20
║ 9 │ 10/1/2018, 12:00:00 AM ║
21
╚═══╧════════════════════════╝
22
23
╔═══╤═══╗
24
║ 0 │ 1 ║
25
╟───┼───╢
26
║ 1 │ 1 ║
27
╟───┼───╢
28
║ 2 │ 1 ║
29
╟───┼───╢
30
║ 3 │ 1 ║
31
╟───┼───╢
32
║ 4 │ 1 ║
33
╟───┼───╢
34
║ 5 │ 1 ║
35
╟───┼───╢
36
║ 6 │ 1 ║
37
╟───┼───╢
38
║ 7 │ 1 ║
39
╟───┼───╢
40
║ 8 │ 1 ║
41
╟───┼───╢
42
║ 9 │ 1 ║
43
╚═══╧═══╝
44
45
╔═══╤═══════════╗
46
║ 0 │ Monday ║
47
╟───┼───────────╢
48
║ 1 │ Thursday ║
49
╟───┼───────────╢
50
║ 2 │ Thursday ║
51
╟───┼───────────╢
52
║ 3 │ Sunday ║
53
╟───┼───────────╢
54
║ 4 │ Tuesday ║
55
╟───┼───────────╢
56
║ 5 │ Friday ║
57
╟───┼───────────╢
58
║ 6 │ Sunday ║
59
╟───┼───────────╢
60
║ 7 │ Wednesday ║
61
╟───┼───────────╢
62
║ 8 │ Saturday ║
63
╟───┼───────────╢
64
║ 9 │ Monday ║
65
╚═══╧═══════════╝
66
67
╔═══╤═══╗
68
║ 0 │ 0 ║
69
╟───┼───╢
70
║ 1 │ 0 ║
71
╟───┼───╢
72
║ 2 │ 0 ║
73
╟───┼───╢
74
║ 3 │ 0 ║
75
╟───┼───╢
76
║ 4 │ 0 ║
77
╟───┼───╢
78
║ 5 │ 0 ║
79
╟───┼───╢
80
║ 6 │ 0 ║
81
╟───┼───╢
82
║ 7 │ 0 ║
83
╟───┼───╢
84
║ 8 │ 0 ║
85
╟───┼───╢
86
║ 9 │ 0 ║
87
╚═══╧═══╝
Copied!
Date time properties of Series or datetime-like columns in DataFrame can be accessed via accessors in the dt name-space. See Accessors
Copy link
Contents
Examples