Graham Quince Posted June 10, 2021 Share Posted June 10, 2021 I've had a school enquiring about how to display the day number for their timetable (they're looking at operating a 10 day calendar, but wanted to make sure that bank holidays etc didn't disrupt the schedule. I thought about trying to automate the whole thing, but then there's always exceptions, so instead I've prepared a spreadsheet which can be adapted. Dates and Day Numbers.xlsx There's code on the DayNo column to identify weekends: =IF(OR(WEEKDAY(A12)=7,WEEKDAY(A12)=1),"Weekend","") and a second sheet which generates the Javascript Object: ="'"&TEXT('Dates and Day No'!A2,"DD/MM/YYYY")&"':'"&'Dates and Day No'!B2&IF('Dates and Day No'!C2<>""," - "&'Dates and Day No'!C2,"")&"'," Which displays the date in date format (Excel likes to convert this to numbers and then displays the corresponding day and any message, to look something like this: '06/09/2021':'4 - National Coding Week' You can then copy the whole second sheet into this code on an HTML widget: <style> .DatesDaysTable { font-size: 19px; border: 1px solid #CCCCCC; text-align: center; } .DatesDaysTable td, .DatesDaysTable th { padding: 10px; border: 1px solid #CCCCCC; } </style> <table class="DatesDaysTable"> <tr> <th>Day No.</th> </tr> </table> <script> var Dates_Days = { //// PASTE IN HERE /// TO HERE /// DELETE LAST COMMA !! }, today = moment().format('DD/MM/YYYY'), thisHTML = arguments[0]; if (Dates_Days[today]) { thisHTML.find('.DatesDaysTable').append( '<tr>'+ '<td>'+Dates_Days[today]+'</td>'+ '</tr>' ); } </script> The variable today uses in the included moment.js to get today's date in the matching format. thisHTML = arguments[0] targets the HTML widget the code is in. And then it is a simple case to display the appropriate information for the current date. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now