date or string type to bigint
up vote
0
down vote
favorite
How can I convert date like '2018-03-31' into bigint
in Hive
?
sql datetime hadoop hive
add a comment |
up vote
0
down vote
favorite
How can I convert date like '2018-03-31' into bigint
in Hive
?
sql datetime hadoop hive
And what format do you want?
– Gordon Linoff
Nov 9 at 11:23
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How can I convert date like '2018-03-31' into bigint
in Hive
?
sql datetime hadoop hive
How can I convert date like '2018-03-31' into bigint
in Hive
?
sql datetime hadoop hive
sql datetime hadoop hive
edited Nov 9 at 11:26
O. Jones
59k971106
59k971106
asked Nov 9 at 11:11
Denis Plotnikov
173
173
And what format do you want?
– Gordon Linoff
Nov 9 at 11:23
add a comment |
And what format do you want?
– Gordon Linoff
Nov 9 at 11:23
And what format do you want?
– Gordon Linoff
Nov 9 at 11:23
And what format do you want?
– Gordon Linoff
Nov 9 at 11:23
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
What Gordon said.
If you have Javascript timestamps, keep in mind that they are simply the number of milliseconds since 1970-01-01T00:00:00.000Z
in 64-bit floating point. They can be converted to BIGINT easily. If you're storing those timestamps in DATETIME(3)
or TIMESTAMP(3)
data types, use UNIX_TIMESTAMP(date)*1000
to get a useful BIGINT millisecond value.
If you only care about dates (not times) you can use TO_DAYS()
to get an integer number of days since 0000-01-01
(in the Gregorian calendar; if you're an historian of antiquity and care about the Julian calendar, this approach has problems. If you don't know what I'm talking about, you don't need to worry.) But INT will suffice for these day numbers; BIGINT is overkill.
Thanks a lot! I got what i had to get in result!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
1
down vote
You could do:
select year(date) * 10000 + month(date) * 100 + day(date)
This produces an integer that represents the date.
If you want a Unix timestamp (seconds since 1970-01-01), then:
select unix_timestamp(date)
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
1
down vote
You can use unix_timestamp
function which converts date or timestamp to a Unix timestamp and returns as a bigint
.
Example query:
select unix_timestamp('2018-03-31', 'yyyy-MM-dd');
Output:
+--------------------------------------+
|unix_timestamp(2018-03-31, yyyy-MM-dd)|
+--------------------------------------+
| 1522434600|
+--------------------------------------+
Note: Tested this code in Hive 1.2.0
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
What Gordon said.
If you have Javascript timestamps, keep in mind that they are simply the number of milliseconds since 1970-01-01T00:00:00.000Z
in 64-bit floating point. They can be converted to BIGINT easily. If you're storing those timestamps in DATETIME(3)
or TIMESTAMP(3)
data types, use UNIX_TIMESTAMP(date)*1000
to get a useful BIGINT millisecond value.
If you only care about dates (not times) you can use TO_DAYS()
to get an integer number of days since 0000-01-01
(in the Gregorian calendar; if you're an historian of antiquity and care about the Julian calendar, this approach has problems. If you don't know what I'm talking about, you don't need to worry.) But INT will suffice for these day numbers; BIGINT is overkill.
Thanks a lot! I got what i had to get in result!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
2
down vote
accepted
What Gordon said.
If you have Javascript timestamps, keep in mind that they are simply the number of milliseconds since 1970-01-01T00:00:00.000Z
in 64-bit floating point. They can be converted to BIGINT easily. If you're storing those timestamps in DATETIME(3)
or TIMESTAMP(3)
data types, use UNIX_TIMESTAMP(date)*1000
to get a useful BIGINT millisecond value.
If you only care about dates (not times) you can use TO_DAYS()
to get an integer number of days since 0000-01-01
(in the Gregorian calendar; if you're an historian of antiquity and care about the Julian calendar, this approach has problems. If you don't know what I'm talking about, you don't need to worry.) But INT will suffice for these day numbers; BIGINT is overkill.
Thanks a lot! I got what i had to get in result!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
What Gordon said.
If you have Javascript timestamps, keep in mind that they are simply the number of milliseconds since 1970-01-01T00:00:00.000Z
in 64-bit floating point. They can be converted to BIGINT easily. If you're storing those timestamps in DATETIME(3)
or TIMESTAMP(3)
data types, use UNIX_TIMESTAMP(date)*1000
to get a useful BIGINT millisecond value.
If you only care about dates (not times) you can use TO_DAYS()
to get an integer number of days since 0000-01-01
(in the Gregorian calendar; if you're an historian of antiquity and care about the Julian calendar, this approach has problems. If you don't know what I'm talking about, you don't need to worry.) But INT will suffice for these day numbers; BIGINT is overkill.
What Gordon said.
If you have Javascript timestamps, keep in mind that they are simply the number of milliseconds since 1970-01-01T00:00:00.000Z
in 64-bit floating point. They can be converted to BIGINT easily. If you're storing those timestamps in DATETIME(3)
or TIMESTAMP(3)
data types, use UNIX_TIMESTAMP(date)*1000
to get a useful BIGINT millisecond value.
If you only care about dates (not times) you can use TO_DAYS()
to get an integer number of days since 0000-01-01
(in the Gregorian calendar; if you're an historian of antiquity and care about the Julian calendar, this approach has problems. If you don't know what I'm talking about, you don't need to worry.) But INT will suffice for these day numbers; BIGINT is overkill.
answered Nov 9 at 11:36
O. Jones
59k971106
59k971106
Thanks a lot! I got what i had to get in result!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
Thanks a lot! I got what i had to get in result!
– Denis Plotnikov
Nov 9 at 13:47
Thanks a lot! I got what i had to get in result!
– Denis Plotnikov
Nov 9 at 13:47
Thanks a lot! I got what i had to get in result!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
1
down vote
You could do:
select year(date) * 10000 + month(date) * 100 + day(date)
This produces an integer that represents the date.
If you want a Unix timestamp (seconds since 1970-01-01), then:
select unix_timestamp(date)
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
1
down vote
You could do:
select year(date) * 10000 + month(date) * 100 + day(date)
This produces an integer that represents the date.
If you want a Unix timestamp (seconds since 1970-01-01), then:
select unix_timestamp(date)
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
1
down vote
up vote
1
down vote
You could do:
select year(date) * 10000 + month(date) * 100 + day(date)
This produces an integer that represents the date.
If you want a Unix timestamp (seconds since 1970-01-01), then:
select unix_timestamp(date)
You could do:
select year(date) * 10000 + month(date) * 100 + day(date)
This produces an integer that represents the date.
If you want a Unix timestamp (seconds since 1970-01-01), then:
select unix_timestamp(date)
answered Nov 9 at 11:23
Gordon Linoff
752k34286394
752k34286394
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
1
down vote
You can use unix_timestamp
function which converts date or timestamp to a Unix timestamp and returns as a bigint
.
Example query:
select unix_timestamp('2018-03-31', 'yyyy-MM-dd');
Output:
+--------------------------------------+
|unix_timestamp(2018-03-31, yyyy-MM-dd)|
+--------------------------------------+
| 1522434600|
+--------------------------------------+
Note: Tested this code in Hive 1.2.0
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
1
down vote
You can use unix_timestamp
function which converts date or timestamp to a Unix timestamp and returns as a bigint
.
Example query:
select unix_timestamp('2018-03-31', 'yyyy-MM-dd');
Output:
+--------------------------------------+
|unix_timestamp(2018-03-31, yyyy-MM-dd)|
+--------------------------------------+
| 1522434600|
+--------------------------------------+
Note: Tested this code in Hive 1.2.0
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
up vote
1
down vote
up vote
1
down vote
You can use unix_timestamp
function which converts date or timestamp to a Unix timestamp and returns as a bigint
.
Example query:
select unix_timestamp('2018-03-31', 'yyyy-MM-dd');
Output:
+--------------------------------------+
|unix_timestamp(2018-03-31, yyyy-MM-dd)|
+--------------------------------------+
| 1522434600|
+--------------------------------------+
Note: Tested this code in Hive 1.2.0
You can use unix_timestamp
function which converts date or timestamp to a Unix timestamp and returns as a bigint
.
Example query:
select unix_timestamp('2018-03-31', 'yyyy-MM-dd');
Output:
+--------------------------------------+
|unix_timestamp(2018-03-31, yyyy-MM-dd)|
+--------------------------------------+
| 1522434600|
+--------------------------------------+
Note: Tested this code in Hive 1.2.0
answered Nov 9 at 11:35
Bhima Rao Gogineni
876
876
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224619%2fdate-or-string-type-to-bigint%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
And what format do you want?
– Gordon Linoff
Nov 9 at 11:23