Pricing Blog

Building a date picker

  • darrenbignall-1128085455351590953

    DarrenBignall

    2 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
  • raphaelwalters-1128122742663811203

    Raphael Walters

    2 years ago

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

    gazinhio

    2 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-1128279891318685738

    DarrenBignall

    2 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 ... 😉
  • erikbeus-1128321474944569448

    Erik Beuschau

    2 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-1128346424669634630

    DarrenBignall

    2 years ago

    You are a legend @Erik Beuschau !!
  • gazinhio-1128410660187943026

    gazinhio

    2 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-1128412211094765609

    gazinhio

    2 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-1128413300422606918

    gazinhio

    2 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-1128414005942300772

    gazinhio

    2 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-1128414010421825566

    Tod

    2 years ago

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

    gazinhio

    2 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-1128416636064509973

    gazinhio

    2 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-1128419487654367364

    gazinhio

    2 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-1128421350877446145

    DarrenBignall

    2 years ago

    That’s amazing pal. Thanks for taking the time to answer that. 👍
  • Tod-1128421352827789412

    Tod

    2 years ago

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

    gazinhio

    2 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-1128422813582250044

    gazinhio

    2 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-1128424052202143764

    DarrenBignall

    2 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-1128424311041036298

    DarrenBignall

    2 years ago

    darren@blincref.com
  • gazinhio-1128426767519076524

    gazinhio

    2 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-1128428147461857320

    DarrenBignall

    2 years ago

    Amazing, appreciate that 🙏 . I am in and looking 👀
    👍1
  • darrenbignall-1128434038332461076

    DarrenBignall

    2 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-1128436755616497854

    gazinhio

    2 years ago

    Great stuff. Look forward to seeing your date picker 👍
  • andreasmoller-1128581291126820935

    Andreas Møller

    2 years ago

    It is possible to clone a public project, if you share the link to it.
    👍2