{"id":3820,"date":"2023-05-12T14:50:07","date_gmt":"2023-05-12T12:50:07","guid":{"rendered":"https:\/\/www.skillup.cloud\/?p=3820"},"modified":"2024-01-23T17:46:42","modified_gmt":"2024-01-23T16:46:42","slug":"snippet-sql-1","status":"publish","type":"post","link":"https:\/\/www.skillup.cloud\/it\/snippet-sql-1\/","title":{"rendered":"Snippet Sql 1"},"content":{"rendered":"\n<p class=\"has-large-font-size\">Come calcolare la differenza tra 2 TimeStamp<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT\n&nbsp; &nbsp; &nbsp; &nbsp;TIMESTAMPDIFF(2, CHAR(\n&nbsp; &nbsp; &nbsp; &nbsp;TIMESTAMP('20230512163211845633') -\n&nbsp; &nbsp; &nbsp; &nbsp;TIMESTAMP('20230512144842274398'))) DIFF_SEC\n&nbsp; FROM SYSIBM.SYSDUMMY1\n\nNota:\nIl primo parametro  di TIMESTAMPDIFF pu\u00f2 assumere i seguenti valori_\n  1&nbsp;&nbsp; &nbsp;Microseconds\n  2&nbsp;&nbsp; &nbsp;Seconds\n  4&nbsp;&nbsp; &nbsp;Minutes\n  8&nbsp;&nbsp; &nbsp;Hours\n 16&nbsp;&nbsp; &nbsp;Days\n 32&nbsp;&nbsp; &nbsp;Weeks\n 64&nbsp;&nbsp; &nbsp;Months\n128&nbsp;&nbsp; &nbsp;Quarters\n256&nbsp;&nbsp; &nbsp;Years\n\nResult:\n---\nDIFF_SEC\n6.209\n---<\/pre>\n\n\n\n<p class=\"has-large-font-size\">Come calcolare la data di &#8220;n&#8221; giorni &#8211; mesi &#8211; anni precedenti \/ successivi<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT\n       CURRENT_DATE - 7 DAYS TODAY7D,\n       CURRENT_DATE - 5 MONTHS TODAY5M,\n       CURRENT_DATE + 2 YEARS TODAY2Y\n  FROM SYSIBM.SYSDUMMY1\n\nResult:\n---\nTODAY7D    TODAY5M    TODAY2Y\n05\/05\/2023    12\/12\/2022    12\/05\/2025\n---<\/pre>\n\n\n\n<p class=\"has-large-font-size\">Come ottenere data e ora correnti in decimale<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT\n       DEC(CURRENT_DATE) TODAY,\n       DEC(CURRENT_TIME) NOW\n  FROM SYSIBM.SYSDUMMY1\n\nResult:\n---\nTODAY        NOW\n20.230.512  120.240\n---<\/pre>\n\n\n\n<p class=\"has-large-font-size\">Come ottenere timestamp correnti in char e in data formattata<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT\n       CHAR(DEC(DEC(CURRENT_TIMESTAMP)*1000000, 20, 0)) TIMESTCHAR,\n       CHAR(DEC(DEC(CURRENT_TIMESTAMP), 14, 0)) TIMECHAR,\n       CHAR(VARCHAR_FORMAT(DATE(TIMESTAMP_FORMAT(CHAR(20230512),\n                           'YYYYMMDD')),'DD\/MM\/YYYY'), 10) DATE\n  FROM SYSIBM.SYSDUMMY1\n\nResult:\n---\nTIMESTCHAR                     TIMECHAR             DATE\n20230512120240100000    20230512120240    12\/05\/2023\n---<\/pre>\n\n\n\n<p class=\"has-large-font-size\">Come ottenere utente corrente<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT\n       CURRENT_USER UTENTE_CORRENTE\n  FROM SYSIBM.SYSDUMMY1\n\nResult:\n---\nUTENTE_CORRENTE\nUSR001\n---<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Come calcolare la differenza tra 2 TimeStamp SELECT &nbsp; &nbsp; &nbsp; &nbsp;TIMESTAMPDIFF(2, CHAR( &nbsp; &nbsp; &nbsp; &nbsp;TIMESTAMP(&#8216;20230512163211845633&#8217;) &#8211; &nbsp; &nbsp; &nbsp; &nbsp;TIMESTAMP(&#8216;20230512144842274398&#8217;))) DIFF_SEC &nbsp; FROM SYSIBM.SYSDUMMY1 Nota: Il primo parametro di TIMESTAMPDIFF pu\u00f2 assumere i seguenti valori_ 1&nbsp;&nbsp; &nbsp;Microseconds 2&nbsp;&nbsp;&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_kadence_starter_templates_imported_post":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[16],"tags":[72,73,29,31,46,70,71],"class_list":["post-3820","post","type-post","status-publish","format-standard","hentry","category-iniziamo-con-alcuni-esempi","tag-varchar_format","tag-current_user","tag-as400","tag-db2","tag-sql","tag-current_date","tag-timestamp"],"_links":{"self":[{"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/posts\/3820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/comments?post=3820"}],"version-history":[{"count":1,"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/posts\/3820\/revisions"}],"predecessor-version":[{"id":3821,"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/posts\/3820\/revisions\/3821"}],"wp:attachment":[{"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/media?parent=3820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/categories?post=3820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillup.cloud\/it\/wp-json\/wp\/v2\/tags?post=3820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}