Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Working with Dates

    2D Blocks
    1
    1
    505
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

       

      Description

      In the “Sensing” category, there are some new blocks provided by the CreatiCode playground to work with dates.

      677028ab-3468-494b-af90-be080d708baa-image.png

       
       

      The “Date” Block

      You can use the “date” block to convert a text input into a “Date” object:

       
      The input may take any of these 5 formats:
       

      d2.gif

       
       

      Date Calculations

      Once you get the Date object, you can use the operator blocks to run basic calculations on dates.

      For example, you can use the add and subtract blocks to calculate the date that’s some days before or after a date:

      You can also use the subtract block to calculate the number of days between 2 dates:

       
       

      Getting the Day of Week/Day/Month/Year of a Date

      These 4 reporter blocks take the date block as the input, and tell us which day of the week/day/month/year is that date:

      Note that for “day of week”, the value 1 means it is a Monday, and the value 7 means it is a Sunday.

       
       

      Example - The First Monday After Some Date

      For example, suppose we want to know the first Monday after the date August 1st, 2023. We can calculate that date in 3 steps:

      1. We need to find out the day of week for 20230801, which is a Tuesday (value of 2)
      2. We need to calculate how many days are there until the following Monday, which is 6 (8 minus 2)
      3. We need to calculate the date that is 6 days after 20230801, which is 20230807.

      Here are the blocks for the calculation in each step:

       
       

      Days Since 2000 for Date

      You can calculate the number of days since the date of Jan 1st, 2000. This is useful if you need to quickly find out the number of days between 2 dates. For example, there are 10 days between these 2 dates:

      e16c685d-5565-4e02-9d39-607b5d7161e8-image.png

      1 Reply Last reply Reply Quote 0
      • First post
        Last post