{"id":799,"date":"2021-05-04T21:48:41","date_gmt":"2021-05-04T16:18:41","guid":{"rendered":"https:\/\/cbsepython.in\/?p=799"},"modified":"2023-12-28T09:59:13","modified_gmt":"2023-12-28T04:29:13","slug":"using-of-datetime-library-in-python","status":"publish","type":"post","link":"https:\/\/cbsepython.in\/using-of-datetime-library-in-python\/","title":{"rendered":"Using of Datetime Library in python Class 11-12 Notes"},"content":{"rendered":"<h1><span style=\"color: #000000;\">Using of Datetime Library in python Class 11-12 Notes<\/span><\/h1>\n<p><span style=\"color: #000000;\">As python provides a large set of library, it also contains datetime library. This library displays the date in <strong>YYYY-MM-DD<\/strong> format. Python datetime module handles the extraction and formatting of date and time variables. All the attributes can be accessed using dot(.) operator with the date object.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">functions in datetime module<\/span><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\"><strong>Date functions<\/strong><\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\"><strong>Description<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\">today( )<\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\">used to display today&#8217;s date<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\">year<\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\">to display year<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\">month<\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\">to display month<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\">day<\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\">to display day<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\"><strong>Time functions<\/strong><\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\"><strong>Description<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\">now()<\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\">used to display current time<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\">hour<\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\">to display hour<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\">minute<\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\">to display minute<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24.4242%;\"><span style=\"color: #000000;\">second<\/span><\/td>\n<td style=\"width: 75.5758%;\"><span style=\"color: #000000;\">to display second<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">today() Implementation:<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import datetime\r\n\r\ndate_today=datetime.date.today()\r\n\r\n#printing today's date\r\nprint(\"Today date is:\",date_today)\r\n\r\n#printing today's year\r\nprint(\"We are in Year:\",date_today.year)\r\n\r\n#printing today's month number\r\nprint(\"Today is\",date_today.month ,\"month of the year\")\r\n\r\n#printing today's day\r\nprint(\"Today is\",date_today.day,\"day of the month\")\r\n\r\n\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">Output:<\/span><\/p>\n<pre><span style=\"color: #000000;\">Today date is: 2022-02-02<\/span>\r\n<span style=\"color: #000000;\">We are in Year: 2022<\/span>\r\n<span style=\"color: #000000;\">Today is 2 month of the year<\/span>\r\n<span style=\"color: #000000;\">Today is 2 day of the month<\/span>\r\n<span style=\"color: #000000;\">&gt;&gt;&gt;<\/span><\/pre>\n<p><strong>Screenshots:<\/strong><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-2629 size-full\" src=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/05\/today_module.jpg\" alt=\"\" width=\"612\" height=\"391\" title=\"\" srcset=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/05\/today_module.jpg 612w, https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/05\/today_module-300x192.jpg 300w, https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/05\/today_module-400x256.jpg 400w\" sizes=\"(max-width: 612px) 100vw, 612px\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2630 size-full\" src=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/05\/today_module_out.jpg\" alt=\"\" width=\"364\" height=\"152\" title=\"\" srcset=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/05\/today_module_out.jpg 364w, https:\/\/cbsepython.in\/wp-content\/uploads\/2021\/05\/today_module_out-300x125.jpg 300w\" sizes=\"(max-width: 364px) 100vw, 364px\" \/><\/p>\n<p><span style=\"color: #000000;\">now() Implementation:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import datetime\r\n\r\ntime_now=datetime.datetime.now()\r\n\r\n#printing current date and time\r\nprint(\"The current time is:\",time_now)\r\n\r\n#printing current hour\r\nprint(\"Current hour is\",time_now.hour)\r\n\r\n#printing current minute\r\nprint(\"Current Minute\",time_now.minute)\r\n\r\n#printing current seconds\r\nprint(\"Current seconds\",time_now.second)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">Output:<\/span><\/p>\n<pre><span style=\"color: #000000;\">The current time is: 2022-02-02 21:32:32.937900<\/span>\r\n<span style=\"color: #000000;\">Current hour is 21<\/span>\r\n<span style=\"color: #000000;\">Current Minute 32<\/span>\r\n<span style=\"color: #000000;\">Current seconds 32<\/span>\r\n<span style=\"color: #000000;\">&gt;&gt;&gt;<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2>Check here- <a href=\"https:\/\/cbsepython.in\/digital-clock-in-python-using-tkinter\/\">digital clock Python Project<\/a><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Using of Datetime Library in python Class 11-12 Notes As python provides a large set of library, it also contains datetime library. This library displays the date in YYYY-MM-DD format. Python datetime module handles the extraction and formatting of date and time variables. All the attributes can be accessed using dot(.) operator with the date [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-799","post","type-post","status-publish","format-standard","hentry","category-cbse-computer-science-with-python-class-12"],"_links":{"self":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/comments?post=799"}],"version-history":[{"count":0,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/799\/revisions"}],"wp:attachment":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/media?parent=799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/categories?post=799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/tags?post=799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}