{"id":2839,"date":"2019-12-13T09:40:24","date_gmt":"2019-12-13T17:40:24","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=2839"},"modified":"2019-12-13T09:40:24","modified_gmt":"2019-12-13T17:40:24","slug":"perl-date-and-concatenation","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=2839","title":{"rendered":"Perl Date and Concatenation"},"content":{"rendered":"<p>I\u2019m working with a legacy script that needs the date in YYYY,MM,DD format and the original programmer went through some contortions to get MySQL to calculate the date and report it out. It seemed to me that perl should be able to do that easily. In fact, it can.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\nmy ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();\nmy $perl_month = $mon + 1;\nmy $perl_year = $year + 1900;\nmy $perl_today = &quot;$perl_year,$perl_month,$mday&quot;;\nmy $perl_today2 = ($year + 1900) . &quot;,&quot; . ($mon + 1) . &quot;,&quot; . $mday;\n\nif ($DEBUG) { print STDOUT &quot;\\n Perl thinks today is: $perl_today, $perl_today2&nbsp;&nbsp;\\n&quot;; }\n\nPerl thinks today is: 2019,12,13, 2019,12,13\n<\/code><\/pre><\/p>\n<p>Perl can do the arithmetic, but you need to put the calculations in parentheses. If you don\u2019t it gets confused and outputs 2020,13. Note that localtime() gives the year as an offset from 1900 and the month starting with January as 0\u2014much like array notation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m working with a legacy script that needs the date in YYYY,MM,DD format and the original programmer went through some contortions to get MySQL to calculate the date and report it out. It seemed to me that perl should be able to do that easily. In fact, it can. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); my $perl_month &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=2839\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Perl Date and Concatenation<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-2839","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2839"}],"version-history":[{"count":1,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2839\/revisions"}],"predecessor-version":[{"id":2840,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2839\/revisions\/2840"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}