{"id":311,"date":"2019-02-15T07:38:49","date_gmt":"2019-02-15T07:38:49","guid":{"rendered":"https:\/\/jan.schnasse.org\/blog\/?p=311"},"modified":"2026-09-28T11:39:16","modified_gmt":"2026-09-28T09:39:16","slug":"unix-tools-introduced-today-date","status":"publish","type":"post","link":"https:\/\/jan.schnasse.org\/blog\/2019\/02\/15\/unix-tools-introduced-today-date\/","title":{"rendered":"Unix tools introduced. Today: date"},"content":{"rendered":"<p>The unix tool date can be used to print the current date. It also can be used to calculate time spans or to reformat time strings.<\/p>\n<p>Examples:<br \/>\n1. Print the current date in a conventional form<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">date +\"%d. %B %Y\"<\/pre>\n<p>2. Use certain locale. Find supported list in <code>\/usr\/share\/i18n\/SUPPORTED<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">LANG=de_DE.UTF-8 date\u00a0+\"%d.\u00a0%B\u00a0%Y\"<\/pre>\n<p>3. Print an arbitrary (but valid) timestring in a conventional form<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">date -d 2003-11-22 +\"%d. %B %Y\"<\/pre>\n<p>4. Print the current date as seconds since 1970 (unix epoche)<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">date +%s<\/pre>\n<p>5. Calculate the difference of two dates in days. Explanation <a href=\"https:\/\/stackoverflow.com\/a\/49728059\/1485527\">can be found here<\/a>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">A=\"2002-10-20\"\nB=\"2003-11-22\"\necho $(( ($(date -d $B +%s) - $(date -d $A +%s)) \/ 86400 )) days<\/pre>\n<p>6. Print seconds after 1970 (unix epoche) in a conventional form.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">TZ=UTC LANG=en_EN.UTF-8  date -d@0 +\"%H:%M:%S %d. %B %Y\"<\/pre>\n<p>Note: if TZ=UTC is left out, date will add or subtract an offset in accordance to systems timezone.<\/p>\n<p>7. Find timezone offset<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">OFF_1=$(date -d '1 Jan' +%z)\nOFF_7=$(date -d '1 Jul' +%z)\necho $OFF_1 $OFF_7<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The unix tool date can be used to print the current date. It also can be used to calculate time spans or to reformat time strings. Examples: 1. Print the current date in a conventional form date +&#8220;%d. %B %Y&#8220; 2. Use certain locale. Find supported list in \/usr\/share\/i18n\/SUPPORTED LANG=de_DE.UTF-8 date\u00a0+&#8220;%d.\u00a0%B\u00a0%Y&#8220; 3. Print an arbitrary [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,17],"tags":[],"class_list":["post-311","post","type-post","status-publish","format-standard","hentry","category-admin","category-unixtools"],"_links":{"self":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/comments?post=311"}],"version-history":[{"count":1,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/311\/revisions"}],"predecessor-version":[{"id":4389,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/311\/revisions\/4389"}],"wp:attachment":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/media?parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/categories?post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/tags?post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}