{"id":1354,"date":"2016-08-01T16:32:02","date_gmt":"2016-08-01T23:32:02","guid":{"rendered":"http:\/\/appinventor.pevest.com\/?p=1354"},"modified":"2016-08-01T16:32:02","modified_gmt":"2016-08-01T23:32:02","slug":"what-day-is-today-finding-the-day-of-the-week-in-app-inventor","status":"publish","type":"post","link":"https:\/\/coldstreams.com\/appinventor\/2016\/08\/01\/what-day-is-today-finding-the-day-of-the-week-in-app-inventor\/","title":{"rendered":"What day is today? Finding the &#8220;Day of the Week&#8221; in App Inventor"},"content":{"rendered":"<p>A reader recently asked how to determine the day of the week &#8211; Monday, Tuesday, Wednesday and so on, using MIT App Inventor code. Obtaining the day of the week is easy, although not obvious.<\/p>\n<h3>Using <em>TimePicker<\/em> and <em>DatePicker<\/em><\/h3>\n<p>I previously posted a tutorial titled &#8220;<a href=\"http:\/\/appinventor.pevest.com\/?p=619\">Using TimePicker and DatePicker for entering time and data information<\/a>&#8220;. Refer to that tutorial for basic information on the handling of time and data information in App Inventor.<\/p>\n<h3>Converting Time Instants into Different Formats<\/h3>\n<p>App Inventor has built-in functions to convert the date into different formats. However, the function to convert a calendar date into the day of the week is not in the <em>DatePicker<\/em> component, but in the <em>Clock<\/em> component.<\/p>\n<p>To demonstrate, we use the original app from the <em>TimePicker<\/em> and <em>DatePicker<\/em> tutorial (you may download the sample code from <a href=\"http:\/\/appinventor.pevest.com\/?p=619\">the original tutorial page<\/a>) and then we add two small bits of code to do identify the day of the week.<\/p>\n<p>In the original sample code, the screen&#8217;s <em>Initialize<\/em> event handler displays the current date and time on screen. To that code, we add the block shown within the yellow rectangle, below:<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2016\/08\/Voila_Capture-2016-08-01_03-02-47_PM.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1355\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2016\/08\/Voila_Capture-2016-08-01_03-02-47_PM-1024x745.gif\" alt=\"Voila_Capture 2016-08-01_03-02-47_PM\" width=\"625\" height=\"455\" \/><\/a><\/p>\n<p>&#8220;<em>call Clock1.Now<\/em>&#8221; returns a value called a <em>time instant<\/em>. The time instant contains both date and time in a special format: the format is not important to us as App Inventor provides routines to convert the time instant into common values like year or hours and minutes.<\/p>\n<p>The <em>Clock<\/em> component has a method &#8220;<em>call Clock1.WeekdayName<\/em>&#8221; that extracts the date information and calculates the day of the week, returning a text string with values like &#8220;Sunday&#8221; or &#8220;Monday&#8221;.<\/p>\n<p>In the original tutorial, the <em>DatePicker<\/em> is used to select a new calendar date (different than what ever the current date is). Once the data is selected with that user interface, the event &#8220;.<em>AfterDateSet<\/em>&#8221; is thrown. Within the AfterDateSet event handler, we extract the <em>Year, Month, Day<\/em> and also the &#8220;<em>WeekdayName<\/em>&#8221; name. To convert the date instant to a day of the week format, we use the <em>WeekdayName<\/em> method of the <em>Clock<\/em> component &#8211; easy but not obvious!<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2016\/08\/Voila_Capture-2016-08-01_03-03-18_PM.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1356\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2016\/08\/Voila_Capture-2016-08-01_03-03-18_PM-1024x340.gif\" alt=\"Voila_Capture 2016-08-01_03-03-18_PM\" width=\"625\" height=\"208\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>Converting a date or time instance into normal formats like Year, Month, Day or day of the week is easy when you use the appropriate conversion functions built in to the App Inventor components.<\/p>\n<p>The weekday value conversion is a little odd in that its hidden in the Clock component. But once you find it, obtaining the day of the week is easy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A reader recently asked how to determine the day of the week &#8211; Monday, Tuesday, Wednesday and so on, using MIT App Inventor code. Obtaining the day of the week is easy, although not obvious. Using TimePicker and DatePicker I previously posted a tutorial titled &#8220;Using TimePicker and DatePicker for entering time and data information&#8220;. &hellip; <a href=\"https:\/\/coldstreams.com\/appinventor\/2016\/08\/01\/what-day-is-today-finding-the-day-of-the-week-in-app-inventor\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">What day is today? Finding the &#8220;Day of the Week&#8221; in App Inventor<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1354","post","type-post","status-publish","format-standard","hentry","category-components"],"_links":{"self":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts\/1354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/comments?post=1354"}],"version-history":[{"count":0,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts\/1354\/revisions"}],"wp:attachment":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/media?parent=1354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/categories?post=1354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/tags?post=1354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}