Announcement

Collapse
No announcement yet.

Check out my script for displaying the Day - Date - Month - Year

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check out my script for displaying the Day - Date - Month - Year

    On a project I wanted to display the date as below

    Sunday 2nd May 2021

    This is how I like to read the date, here in the UK.

    I found an old thread and got the basics of how to get near what I wanted.

    So I elaborated on the script and came up with this

    Code:
    -- Day Of The Week
    DayName = {}
    DayName[1]= "Sunday";
    DayName[2]= "Monday";
    DayName[3]= "Tuesday";
    DayName[4]= "Wednesday";
    DayName[5]= "Thursday";
    DayName[6]= "Friday";
    DayName[7]= "Saturday";
    Result1 = String.ToNumber(System.GetDate(DATE_FMT_DAYOFWEEK) );
    -- End Of - Day Of The Week
    
    -- Day Of The Month
    DayOfTheMonth = {}
    DayOfTheMonth[1] = "1st"
    DayOfTheMonth[2] = "2nd"
    DayOfTheMonth[3] = "3rd"
    DayOfTheMonth[4] = "4th"
    DayOfTheMonth[5] = "5th"
    DayOfTheMonth[6] = "6th"
    DayOfTheMonth[7] = "7th"
    DayOfTheMonth[8] = "8th"
    DayOfTheMonth[9] = "9th"
    DayOfTheMonth[10] = "10th"
    DayOfTheMonth[11] = "11th"
    DayOfTheMonth[12] = "12th"
    DayOfTheMonth[13] = "13th"
    DayOfTheMonth[14] = "14th"
    DayOfTheMonth[15] = "15th"
    DayOfTheMonth[16] = "16th"
    DayOfTheMonth[17] = "17th"
    DayOfTheMonth[18] = "18th"
    DayOfTheMonth[19] = "19th"
    DayOfTheMonth[20] = "20th"
    DayOfTheMonth[21] = "21st"
    DayOfTheMonth[22] = "22nd"
    DayOfTheMonth[23] = "23rd"
    DayOfTheMonth[24] = "245th"
    DayOfTheMonth[25] = "25th"
    DayOfTheMonth[26] = "26th"
    DayOfTheMonth[27] = "27th"
    DayOfTheMonth[28] = "28th"
    DayOfTheMonth[29] = "29th"
    DayOfTheMonth[30] = "30th"
    DayOfTheMonth[31] = "31st"
    Result2 = String.ToNumber(System.GetDate(DATE_FMT_DAY));
    -- End Of - Day Of The Month
    
    -- Month
    MonthName = {}
    MonthName[1]= "January";
    MonthName[2]= "February";
    MonthName[3]= "March";
    MonthName[4]= "April";
    MonthName[5]= "May";
    MonthName[6]= "June";
    MonthName[7]= "July";
    MonthName[8]= "August";
    MonthName[9]= "September";
    MonthName[10]= "October";
    MonthName[11]= "November";
    MonthName[12]= "December";
    Result3 = String.ToNumber(System.GetDate(DATE_FMT_MONTH));
    -- End Of - Month
    
    -- Year
    Year = System.GetDate(DATE_FMT_YEAR);
    -- End Of Year
    
    -- Complete Output
    --Paragraph.SetText("Paragraph1", DayName[Result1].." "..DayOfTheMonth[Result2].." "..MonthName[Result3].." "..Year);
    Dialog.Message("Todays Date",DayName[Result1].." "..DayOfTheMonth[Result2].." "..MonthName[Result3].." "..Year, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    -- End Of - Complete Output
    I was wondering what you pro's thought of it . Does it look ok or could it be made simpler ?

    I have had lots and lots of help and not really given nowt back...

    Somebody may find this useful.

    I will test it out each day and see if I have things right..


  • #2
    Great, but you can define this code as a new function in Global Function to get rid of copying and pasting code ...

    Comment


    • #3
      other way (date.lua)

      globals:
      require"date";


      Click image for larger version

Name:	screen.PNG
Views:	223
Size:	11.3 KB
ID:	306924


      Comment


      • #4
        Thanks herrin.

        I have copied your script but I must be doing something wrong.
        I get errors.

        Looks a whole lot neater than my effort.

        Any chance you could up an example for me to look at please, if you get a mo.

        Comment


        • #5
          herrin..

          What I have noticed about your script is the "nd"

          If it was the 01 or 21 or 31 it should end in "st"
          If it was 02 or 22 it should end in "nd"
          if it was 03 or 23 is should end in "rd"
          The rest should end in "th"

          Can your script accommodate this ?


          I was Goggling round and found this
          Code:
          prettyNow = os.date('%A %B %d %Y at %I:%M:%S %p')
          which I altered to

          Code:
          prettyNow = os.date('%A %B %d %Y at %H:%M')
          Dialog.Message("Notice", prettyNow, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
          I still like when it says " st, nd, rd , th "

          Comment


          • #6
            seems I am missing a "module" "luaddate" madule

            No idea what this is, or where to find it...

            Looking now..

            Comment


            • #7
              Think I have the module now..

              from here

              Comment


              • #8
                Click image for larger version

Name:	Cattura.PNG
Views:	182
Size:	26.9 KB
ID:	306941

                Comment


                • #9
                  That looks cool herrin..

                  Comment

                  Working...
                  X