{"id":257,"date":"2022-10-05T20:49:48","date_gmt":"2022-10-05T12:49:48","guid":{"rendered":"https:\/\/islandtropicaman.com\/wp\/?p=257"},"modified":"2022-10-05T20:55:19","modified_gmt":"2022-10-05T12:55:19","slug":"python-datetime-module","status":"publish","type":"post","link":"https:\/\/islandtropicaman.com\/wp\/2022\/10\/05\/python-datetime-module\/","title":{"rendered":"Python Datetime Module"},"content":{"rendered":"<p>Python datetime module allows you to create an datetime object or get the date of a particular day. Let me create a few examples to demonstrate to you how to use the methods of this DateTime module.<\/p>\n<p>Find the present date and day, month, etc.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nimport datetime\r\n\r\ncurrent_date = datetime.datetime.now()\r\nprint(current_date.strftime(&quot;%A&quot;)) #Weekday\r\nprint(current_date.strftime(&quot;%w&quot;)) #Weekday as a number 0-6, 0 is Sunday\r\nprint(current_date.strftime(&quot;%d&quot;)) #Day of month \r\nprint(current_date.strftime(&quot;%B&quot;)) #Month name\r\nprint(current_date.strftime(&quot;%m&quot;)) #Month as a number 01-12\r\nprint(current_date.strftime(&quot;%Y&quot;)) #Year\r\nprint(current_date.strftime(&quot;%H&quot;)) #Hour from 00 - 23\r\nprint(current_date.strftime(&quot;%p&quot;)) #AM\/PM\r\nprint(current_date.strftime(&quot;%M&quot;)) #Minute\r\nprint(current_date.strftime(&quot;%S&quot;)) #Second\r\nprint(current_date.strftime(&quot;%C&quot;)) #Century\r\nprint(current_date.strftime(&quot;%j&quot;)) #Day number of year \r\n<\/pre>\n<p>As you can see that the strftime method above will accept a string parameter which is uses to retrieve the value of a particular element within that particular date, such as a weekday.<\/p>\n<p>Below are the outcomes of the above program.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nWednesday\r\n3\r\n05\r\nOctober\r\n10\r\n2022\r\n20\r\nPM\r\n20\r\n26\r\n20\r\n278\r\n<\/pre>\n<p>Another method to use the datetime object is to create your datetime object as follows:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\ncurrent_time = datetime.datetime(2022, 10, 5)\r\n<\/pre>\n<p>There are still lots of fantastic Python modules that I will leave to you to explore and thus I will conclude the Module area of the Python programming language.<\/p>\n<p>In the coming article, I will start to create a python program thus letting us learn together how to write Python code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python datetime module allows you to create an datetime object or get the date of a particular day. Let me create a few examples to demonstrate to you how to use the methods of this DateTime module. Find the present date and day, month, etc. import datetime current_date = datetime.datetime.now() print(current_date.strftime(&quot;%A&quot;)) #Weekday print(current_date.strftime(&quot;%w&quot;)) #Weekday as&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"https:\/\/islandtropicaman.com\/wp\/2022\/10\/05\/python-datetime-module\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;Python Datetime Module&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,72],"tags":[76,75],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-python","category-python-tutorial","tag-datetime","tag-python-datetime-module"],"blog_post_layout_featured_media_urls":{"thumbnail":"","full":""},"categories_names":{"8":{"name":"Python","link":"https:\/\/islandtropicaman.com\/wp\/category\/python\/"},"72":{"name":"Python Tutorial","link":"https:\/\/islandtropicaman.com\/wp\/category\/python-tutorial\/"}},"tags_names":{"76":{"name":"datetime","link":"https:\/\/islandtropicaman.com\/wp\/tag\/datetime\/"},"75":{"name":"Python Datetime Module","link":"https:\/\/islandtropicaman.com\/wp\/tag\/python-datetime-module\/"}},"comments_number":"0","_links":{"self":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":2,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":259,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/257\/revisions\/259"}],"wp:attachment":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}