Round date to day

  • ssssadsadasd-1372504750616088607

    ssssadsadasd

    2 days ago

    [Here](https://toddle.dev/projects/moccasin_palpatine_chief_rook/branches/start/components/test99?selection=nodes.MHfCYq9evFtu3TFfqeLzM.value&rightpanel=style), I want to create a date 14 days from now rounded to 00:00:00 in UTC time.
    adding the 14 days is fairly simple (now -> timestamp -> add 1209600000 seconds -> date from timestamp) but I dont know how to round this to a day and make hours=minutes=seconds = 0
    anyone has any idea?
    thanks
  • erikbeus-1372506437854691398

    Erik Beuschau

    2 days ago

  • filip_dajkovic-1372507495943114855

    Filip Dajkovic

    2 days ago

    You could use a custom JS formula with '.setHours(0,0,0,0)' date method, keep in mind that custom formulas don't run server-side.
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours
  • ssssadsadasd-1372565138988601424

    ssssadsadasd

    2 days ago

    I think those formulas are for formatting only
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
    🤦‍♂️1
  • filip_dajkovic-1372573452598513784

    Filip Dajkovic

    2 days ago

    Well you could use it in a way to get only hours, minutes, seconds number in UTC and than subtract that from the timestamp, it's painful but possible
  • erikbeus-1372574222311751741

    Erik Beuschau

    2 days ago

    That’s true. I’ll check if I can come up with a better example 👍
  • ssssadsadasd-1372581186337116311

    ssssadsadasd

    2 days ago

    @Filip Dajkovic this function did the work for me

    /**
    * @param {Args} args
    * @param {Ctx} ctx
    */
    function setHours(args, ctx) {
    const now = new Date();

    // Create a new UTC-based date (in ms) + 14 days
    const utc = new Date(
    Date.UTC(
    now.getUTCFullYear(),
    now.getUTCMonth(),
    now.getUTCDate() + 14, // add 14 days
    0, 0, 0, 0 // set to midnight UTC
    )
    );

    return utc;
    }
  • filip_dajkovic-1372587716860055602

    Filip Dajkovic

    2 days ago

    Great, glad it works!