Cast Invalid Error

Hi All,

I found some strange behavior with the below expressions related to date and time.

{
  /* All these worked */
  now() + second() * 62,
  now() + minute() * 5,
  now() + hour() * 5,
  now() + day() * 5,
  
  /* These didn't work */
  now() + month() * 5,
  now() + year() * 5
}

Can someone please explain why the last 2 statements don't work, and throw cast invalid error?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    All the working ones return value in interval day to second while month() and year() return value in interval year to month. One way to make this work is by converting data returned from month() and year() into interval of day to second. You can use the function tointervalds() to achieve this.

     

    {
      /* All these worked */
      now() + second() * 62,
      now() + minute() * 5,
      now() + hour() * 5,
      now() + day() * 5,
      
      now() + tointervalds(month())*5 ,
      now() + tointervalds(year())*5 
    }

Reply
  • 0
    Certified Lead Developer

    All the working ones return value in interval day to second while month() and year() return value in interval year to month. One way to make this work is by converting data returned from month() and year() into interval of day to second. You can use the function tointervalds() to achieve this.

     

    {
      /* All these worked */
      now() + second() * 62,
      now() + minute() * 5,
      now() + hour() * 5,
      now() + day() * 5,
      
      now() + tointervalds(month())*5 ,
      now() + tointervalds(year())*5 
    }

Children