{"id":1213,"date":"2018-08-24T12:03:02","date_gmt":"2018-08-24T10:03:02","guid":{"rendered":"http:\/\/pythonprogramming.altervista.org\/?p=1213"},"modified":"2018-08-27T07:54:04","modified_gmt":"2018-08-27T05:54:04","slug":"show-the-date-with-datetime","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/show-the-date-with-datetime\/","title":{"rendered":"Show the date with datetime"},"content":{"rendered":"<p><a href=\"http:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/08\/datetime.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1214\" src=\"http:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/08\/datetime.png\" alt=\"\" width=\"1024\" height=\"512\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/08\/datetime.png 1024w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/08\/datetime-320x160.png 320w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/08\/datetime-768x384.png 768w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/08\/datetime-960x480.png 960w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>The datetime module is useful to get the date in our programs.<br \/>\nLet&#8217;s take a look at it.<\/p>\n<h2>The methods<\/h2>\n<p>Let&#8217;s use dir to see the methods in datetime.<\/p>\n<pre class=\"lang:default decode:true \">from datetime import datetime\r\n\r\nnow = datetime.today()\r\nfor method in dir(now):\r\n\tif not method.startswith(\"__\"):\r\n\t\tprint(method)<\/pre>\n<p>Running this script we will get this output:<\/p>\n<pre class=\"lang:default decode:true \">astimezone\r\ncombine\r\nctime\r\ndate\r\nday\r\ndst\r\nfold\r\nfromisoformat\r\nfromordinal\r\nfromtimestamp\r\nhour\r\nisocalendar\r\nisoformat\r\nisoweekday\r\nmax\r\nmicrosecond\r\nmin\r\nminute\r\nmonth\r\nnow\r\nreplace\r\nresolution\r\nsecond\r\nstrftime\r\nstrptime\r\ntime\r\ntimestamp\r\ntimetuple\r\ntimetz\r\ntoday\r\ntoordinal\r\ntzinfo\r\ntzname\r\nutcfromtimestamp\r\nutcnow\r\nutcoffset\r\nutctimetuple\r\nweekday\r\nyear\r\n&gt;&gt;&gt;<\/pre>\n<h2>Write the date in a certain way<\/h2>\n<pre class=\"lang:default decode:true \">from datetime import datetime\r\n\r\nnow = datetime.today()\r\n\r\ndate = f\"{now.day}\/{now.month}\/{now.year}\"\r\n\r\nprint(date)<\/pre>\n<p>The output:<\/p>\n<pre class=\"lang:default decode:true \" >24\/8\/2018\r\n&gt;&gt;&gt; <\/pre>\n<p><iframe loading=\"lazy\" width=\"100%\" height=\"400\" src=\"https:\/\/www.youtube.com\/embed\/wtDTfn67qMQ\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"Insert the date in Python with datetime, in different ways.\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/show-the-date-with-datetime\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":1214,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[250,248,4,249],"class_list":["post-1213","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples","tag-date","tag-datetime","tag-python","tag-time"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":false,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/1213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=1213"}],"version-history":[{"count":2,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/1213\/revisions"}],"predecessor-version":[{"id":1216,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/1213\/revisions\/1216"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/1214"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=1213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=1213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=1213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}