Jump to content
Graham Quince

Message per day, day name etc...

Recommended Posts

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...