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?










share|improve this question























  • And what format do you want?
    – Gordon Linoff
    Nov 9 at 11:23














up vote
0
down vote

favorite












How can I convert date like '2018-03-31' into bigint in Hive?










share|improve this question























  • And what format do you want?
    – Gordon Linoff
    Nov 9 at 11:23












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?










share|improve this question















How can I convert date like '2018-03-31' into bigint in Hive?







sql datetime hadoop hive






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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












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.






share|improve this answer




















  • Thanks a lot! I got what i had to get in result!
    – Denis Plotnikov
    Nov 9 at 13:47

















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)





share|improve this answer




















  • Thanks a lot! I understood!
    – Denis Plotnikov
    Nov 9 at 13:47

















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






share|improve this answer




















  • Thanks a lot! I understood!
    – Denis Plotnikov
    Nov 9 at 13:47











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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

























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.






share|improve this answer




















  • Thanks a lot! I got what i had to get in result!
    – Denis Plotnikov
    Nov 9 at 13:47














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.






share|improve this answer




















  • Thanks a lot! I got what i had to get in result!
    – Denis Plotnikov
    Nov 9 at 13:47












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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












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)





share|improve this answer




















  • Thanks a lot! I understood!
    – Denis Plotnikov
    Nov 9 at 13:47














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)





share|improve this answer




















  • Thanks a lot! I understood!
    – Denis Plotnikov
    Nov 9 at 13:47












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)





share|improve this answer












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)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 11:23









Gordon Linoff

752k34286394




752k34286394











  • 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




Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47










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






share|improve this answer




















  • Thanks a lot! I understood!
    – Denis Plotnikov
    Nov 9 at 13:47















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






share|improve this answer




















  • Thanks a lot! I understood!
    – Denis Plotnikov
    Nov 9 at 13:47













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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 11:35









Bhima Rao Gogineni

876




876











  • 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





Thanks a lot! I understood!
– Denis Plotnikov
Nov 9 at 13:47


















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế