Help forum

Building a date picker

  • DarrenBignall

    3 years ago

    I want to build a date picker component, but think I'd need more date functions (getFullYear, getMonth, getDate and getDay) to allow me to work out the amount of days in month, day of week on 1st day. Would there be another way to handle this, wothout these functions?
    ๐Ÿ‘1
  • Raphael Walters

    3 years ago

    Very interested to hear everyone's thoughts on this too as a date picker is on my todo list.
  • gazinhio

    3 years ago

    Do you need to know how to get the last day of month, the day of a month, the month of a date etc out of a date?
  • DarrenBignall

    3 years ago

    Yeah, so the user will have a month and year selected and I need to know how to display:
    1. The correct number of days for that month (and year for leap years) - so last day of the given month would be perfect
    2. The day of week of the 1st day of month so I can correctly display the days

    Feels like I don't have enough functions to achieve this at the mo, but feel like you are about to tell me different ... ๐Ÿ˜‰
  • Erik Beuschau

    3 years ago

    Great question @DarrenBignall ๐Ÿ‘ We'll see if we can add a few more functions to help you out using dates. At least it's not easy to achieve atm using the Format Date formula. Stay tuned ๐Ÿ™‚
  • DarrenBignall

    3 years ago

    You are a legend @Erik Beuschau !!
  • gazinhio

    3 years ago

    In leau of the Toddle guys adding the functionality here's a couple of things that might help ...
  • First of all create an array called "daysInMonth"
  • gazinhio

    3 years ago

    Create a formula called MonthNumberFromDate. This takes a timestamp as an input and spits out the month number ...
    1128412210763399284-daysinmonth1.png
  • 1128412376035770469-daysinmonth2.png
  • gazinhio

    3 years ago

    We need to formula which tell us how many days in February based on whether it's a leap year, so create another formula called IsLeapYear ..
    1128413300124823613-daysinmonth3.png
  • This again takes a timestamp and spits out a boolean based on whether it's a leap year or not.
  • gazinhio

    3 years ago

    Next we need a formula which returns the actual number of days in Feb, which relies on the IsLeapYear formula ...
    1128414005678055575-daysinmonth4.png
  • Tod

    3 years ago

    Great energy @! Your continuous contribution to the toddle Community just made you advance to Community Level 3!
  • gazinhio

    3 years ago

    Ooops sorry, you'll also need a YearFromDate formula which takes a timestamp and returns the year as a number ...
    1128415653318115348-daysinmonth5.png
  • gazinhio

    3 years ago

    Finally ..... the formula which returns the number of days in the month callled NumberOfDaysInMonth, again takes a timestamp and returns the number of days in the month of the date ....
    1128416635858984960-daysinmonth6.png
  • gazinhio

    3 years ago

    To get the day of the week from the first of a month, create a formula called FirstDayNameInMonth, this take a timestamp as an input and spits out the first three letters of the day of the week of the first day, it uses the date format returned by Toddle, converts it to a string and "Takes" it's first 3 characters which is the day of the week. A bit cheeky but it works ๐Ÿ˜‰
    1128419487394299995-daysinmonth7.png
    ๐Ÿ™1
  • @ just finished his days work โ€ฆ
  • DarrenBignall

    3 years ago

    Thatโ€™s amazing pal. Thanks for taking the time to answer that. ๐Ÿ‘
  • Tod

    3 years ago

    Great energy @DarrenBignall! Your continuous contribution to the toddle Community just made you advance to Community Level 8!
  • gazinhio

    3 years ago

    ๐Ÿคฃ No worries. Looking forward to when we can share formulas with others, I know the fellaz are working on it (with a thousand and one other things) but it will really open things up. ๐Ÿ‘
  • gazinhio

    3 years ago

    Actually is there a way to share this test project with you to look at? If so I've not seen it yet?
  • DarrenBignall

    3 years ago

    if it is a test project with nothing else in it then i think you can add me as a member on the free plan ...
  • DarrenBignall

    3 years ago

    darren@blincref.com
  • gazinhio

    3 years ago

    I've invited you now. It's in the Demo2 branch and the DateTest page. Feel free to have a look around, there are a lot of formulas that were just for playing & testing so not all work, the one's I mentioned above work as advertised ๐Ÿคž if you need anything in particular just let me know ๐Ÿ‘
  • DarrenBignall

    3 years ago

    Amazing, appreciate that ๐Ÿ™ . I am in and looking ๐Ÿ‘€
    ๐Ÿ‘1
  • DarrenBignall

    3 years ago

    I can copy the formulas out of your project pretty easily ๐Ÿ‘ just need to copy the card just before the output and can then paste that into a formula in my project ๐Ÿ‘Œ
  • gazinhio

    3 years ago

    Great stuff. Look forward to seeing your date picker ๐Ÿ‘
  • Andreas Mรธller

    3 years ago

    It is possible to clone a public project, if you share the link to it.
    ๐Ÿ‘2